CSFML
Functions
Thread.h File Reference
`#include <SFML/System/Export.h>`
`#include <SFML/System/Types.h>`

Go to the source code of this file.

## Functions

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

## Function Documentation

## ◆ sfThread_create()

CSFML_SYSTEM_API 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

  function | Entry point of the thread
  userData | Custom data to pass to the thread function

Returns
  A new sfThread object

## ◆ sfThread_destroy()

CSFML_SYSTEM_API 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

  thread | Thread to destroy

## ◆ sfThread_launch()

CSFML_SYSTEM_API 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

  thread | Thread object

## ◆ sfThread_terminate()

CSFML_SYSTEM_API 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

  thread | Thread object

## ◆ sfThread_wait()

CSFML_SYSTEM_API 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

  thread | Thread object