DungeonCrawl
Loading...
Searching...
No Matches
thread_handler.h File Reference

Exposes functions for the thread_handler. More...

Go to the source code of this file.

Functions

void start_simple_thread (void(*thread_func)(void))
 Starts a new thread with the given function.

Detailed Description

Exposes functions for the thread_handler.

Definition in file thread_handler.h.

Function Documentation

◆ start_simple_thread()

void start_simple_thread ( void(* thread_func )(void))

Starts a new thread with the given function.

The thread will be detached, so it will run independently.

Parameters
thread_funcA simple function pointer to the function that will be executed in the thread.

Definition at line 56 of file thread_handler.c.

56 {
57 pthread_t thread;
58 thread_func_wrapper_t* arg = malloc(sizeof(thread_func_wrapper_t));
59 if (!arg) return;// Fehlerbehandlung
60 arg->func = thread_func;
61
62 if (pthread_create(&thread, NULL, thread_wrapper, arg) == 0) {
63 pthread_detach(thread);// Detach den Thread
64 } else {
65 free(arg);// Fehlerbehandlung
66 }
67}
void * thread_wrapper(void *arg)
A wrapper function arround a thread for multi platform thread implementation.