Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static initialization of mtx_t using threads.h

threads.h supports only dynamic mutex initialization with mtx_init().

Aparently there isn't any info on the internet regarding threads.h apart from: http://en.cppreference.com/w/c/thread.( I would really like to know if there is something more)

Does anyone know how is struct mtx_t in threads.h implemented? I would like to init the mutex statically like in pthreads ( PTHREAD_MUTEX_INITIALIZER ), to avoid calling initialization function every time at the start of the program.

like image 538
this Avatar asked Sep 14 '26 13:09

this


1 Answers

There is no ability of the C11 threads.h to initialize a mutex without calling mtx_init()

threads.h is implemented differently on different platforms - so knowing the implementation detail of how a mtx_t actually look like would't be of much use, you'd be just as well off using the native thread api if it exists, such as pthreads which does provide this ability.

like image 108
nos Avatar answered Sep 16 '26 07:09

nos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!