MPMT v1.7.4
thread.h File Reference

Common thread functions. More...

#include <stddef.h>
#include <stdbool.h>

Typedefs

typedef struct Thread_T Thread_T
 Thread structure.
 
typedef Thread_TThread
 Thread instance.
 

Functions

Thread createThread (void(*function)(void *), void *argument)
 Creates a new thread executing the specified function.
 
void destroyThread (Thread thread)
 Destroys thread instance.
 
void joinThread (Thread thread)
 Blocks the current thread until the function execution end.
 
void sleepThread (double delay)
 Blocks the execution of the current thread for a specified time.
 
bool yieldThread ()
 Causes the current thread to yield execution to another thread.
 
bool isThreadJoined (Thread thread)
 Returns thread current join status.
 
bool isThreadCurrent (Thread thread)
 Returns true if thread is currently running one.
 
const void * getThreadNative (Thread thread)
 Returns pointer to the native thread handle.
 
void setMainThread ()
 Sets current thread as main.
 
bool isCurrentThreadMain ()
 Returns true if current thread is main.
 
bool isThreadMain (Thread thread)
 Returns true if thread is main.
 
void getThreadName (char *name, size_t size)
 Returns current thread name.
 
void setThreadName (const char *name)
 Sets current thread name.
 
void setThreadForegroundPriority ()
 Sets current thread priority to foreground.
 
void setThreadBackgroundPriority ()
 Sets current thread priority to background.
 

Detailed Description

Common thread functions.

A thread is the smallest unit of execution within a process. Threads are parallel execution paths that can run independently but share the same resources, such as memory space, file descriptors, and other process-specific information. Threads enable concurrent execution and can be used to perform multiple tasks simultaneously within a single process.

Function Documentation

◆ createThread()

Thread createThread ( void(* function )(void *),
void * argument )

Creates a new thread executing the specified function.

Threads begin execution immediately upon construction of the associated thread object (pending any OS scheduling delays), starting at the top-level function provided as a constructor argument.

Parameters
[in]functionpointer to the function that should be invoked
[in]argumentargument that will be passed to the function or NULL
Returns
Thread instance on success, otherwise NULL.

◆ destroyThread()

void destroyThread ( Thread thread)

Destroys thread instance.

Parameters
threadthread instance or NULL

◆ joinThread()

void joinThread ( Thread thread)

Blocks the current thread until the function execution end.

Parameters
threadthread instance

◆ sleepThread()

void sleepThread ( double delay)

Blocks the execution of the current thread for a specified time.

Parameters
delaythread sleep delay time (in seconds)

◆ yieldThread()

bool yieldThread ( )

Causes the current thread to yield execution to another thread.

Returns
True on success, otherwise false.

◆ isThreadJoined()

bool isThreadJoined ( Thread thread)

Returns thread current join status.

Parameters
threadthread instance

◆ isThreadCurrent()

bool isThreadCurrent ( Thread thread)

Returns true if thread is currently running one.

Parameters
threadthread instance

◆ getThreadNative()

const void * getThreadNative ( Thread thread)

Returns pointer to the native thread handle.

Warning
You should not free returned pointer or use it after thread destruction.
Parameters
threadthread instance

◆ isThreadMain()

bool isThreadMain ( Thread thread)

Returns true if thread is main.

Parameters
threadtarget thread instance

◆ getThreadName()

void getThreadName ( char * name,
size_t size )

Returns current thread name.

Parameters
[out]namepointer to the thread name string
sizemaximal name string capacity (including '\0')

◆ setThreadName()

void setThreadName ( const char * name)

Sets current thread name.

Parameters
[in]namethread name string