Loading...
Searching...
No Matches
Thread.h File Reference

Go to the source code of this file.

Functions

sfThreadsfThread_create (void(*function)(void *), void *userData)
 Create a new thread from a function pointer.
 
void sfThread_destroy (sfThread *thread)
 Destroy a thread.
 
void sfThread_launch (sfThread *thread)
 Run a thread.
 
void sfThread_wait (sfThread *thread)
 Wait until a thread finishes.
 
void sfThread_terminate (sfThread *thread)
 Terminate a thread.
 

Function Documentation

◆ sfThread_create()

sfThread * sfThread_create ( void(*)(void *)  function,
void *  userData 
)

Create a new thread from a function pointer.

Note: this does not run the thread, use sfThread_launch.

Parameters
functionEntry point of the thread
userDataCustom data to pass to the thread function
Returns
A new sfThread object

◆ sfThread_destroy()

void sfThread_destroy ( sfThread thread)

Destroy a thread.

This function calls sfThread_wait, so that the internal thread cannot survive after the sfThread object is destroyed.

Parameters
threadThread to destroy

◆ sfThread_launch()

void sfThread_launch ( sfThread thread)

Run a thread.

This function starts the entry point passed to the thread's constructor, and returns immediately. After this function returns, the thread's function is running in parallel to the calling code.

Parameters
threadThread object

◆ sfThread_terminate()

void sfThread_terminate ( sfThread thread)

Terminate a thread.

This function immediately stops the thread, without waiting for its function to finish. Terminating a thread with this function is not safe, and can lead to local variables not being destroyed on some operating systems. You should rather try to make the thread function terminate by itself.

Parameters
threadThread object

◆ sfThread_wait()

void sfThread_wait ( sfThread thread)

Wait until a thread finishes.

This function will block the execution until the thread's function ends. Warning: if the thread function never ends, the calling thread will block forever. If this function is called from its owner thread, it returns without doing anything.

Parameters
threadThread object