Typedefs | Functions
thread.h File Reference

Threading support. More...

Typedefs

typedef struct vtm_thread vtm_thread
 
typedef int(* vtm_thread_func )(void *arg)
 

Functions

VTM_API vtm_thread * vtm_thread_new (vtm_thread_func func, void *arg)
 
VTM_API void vtm_thread_free (vtm_thread *th)
 
VTM_API int vtm_thread_signal (vtm_thread *th, enum vtm_signal_type sig)
 
VTM_API int vtm_thread_cancel (vtm_thread *th)
 
VTM_API int vtm_thread_join (vtm_thread *th)
 
VTM_API bool vtm_thread_running (vtm_thread *th)
 
VTM_API int vtm_thread_get_result (vtm_thread *th)
 
VTM_API unsigned long vtm_thread_get_id (vtm_thread *th)
 
VTM_API unsigned long vtm_thread_get_current_id ()
 
VTM_API void vtm_thread_sleep (unsigned int millis)
 

Function Documentation

VTM_API vtm_thread* vtm_thread_new ( vtm_thread_func  func,
void *  arg 
)

Starts a new thread.

Parameters
functhe function which should be executed as new thread
argthe arguments which are passed to the new thread
Returns
a handle to the created thread
NULL if the thread could not be created
VTM_API void vtm_thread_free ( vtm_thread *  th)

Frees the thread and all allocated resources.

Parameters
ththe thread which should be freed
VTM_API int vtm_thread_signal ( vtm_thread *  th,
enum vtm_signal_type  sig 
)

Sends a signal to a specific thread.

This is not supported on all platforms.

Parameters
ththe thread which should receive the signal
sigthe signal which sould be sent
Returns
VTM_OK if the signal was successfully sent
VTM_E_NOT_SUPPORTED if operation not supported on current platform
VTM_API int vtm_thread_cancel ( vtm_thread *  th)

Trys to stop a running thread.

This is not supported on all platforms.

Parameters
ththe thread which should be stopped.
Returns
VTM_OK if the cancelation request was successful
VTM_E_NOT_SUPPORTED if operation not supported on current platform
VTM_ERROR if the cancelation was not successful
VTM_API int vtm_thread_join ( vtm_thread *  th)

Blocks until the given thread has finished.

Parameters
ththe thread which should be joined
Returns
VTM_OK if the operation succeed
VTM_ERROR if the join was not successful
VTM_API bool vtm_thread_running ( vtm_thread *  th)

Checks if given thread is running.

Parameters
ththe thread which should be checked
Returns
true if the thread is running, false otherwise
VTM_API int vtm_thread_get_result ( vtm_thread *  th)

Gets the result code of given thread.

Parameters
ththe thread whose result is read
Returns
the result code of the thread
VTM_API unsigned long vtm_thread_get_id ( vtm_thread *  th)

Get the unique id of the given thread.

Note: the format of the ids is not comparable between different platforms.

Parameters
ththe thread whose id should be read
Returns
the unique id
VTM_API unsigned long vtm_thread_get_current_id ( )

Get the unique id of the current thread.

Note: the format of the ids is not comparable between different platforms.

Returns
the unique id
VTM_API void vtm_thread_sleep ( unsigned int  millis)

Let the current thread sleep.

It is not guaranteed that the thread sleeps the complete interval, the sleep could be interrupted by a signal.

Parameters
millisthe amount of milliseconds the thread should sleep