Thread Safety in C

前端 未结 9 2046
余生分开走
余生分开走 2021-02-02 01:01

imagine I write a library in C. Further, imagine this library to be used from a multi-threaded environment. How do I make it thread-safe? More specific: How do

9条回答
  •  青春惊慌失措
    2021-02-02 01:24

    You will need to use your OS's threading library. On Posix, that will usually be pthreads and you'll want pthread_mutex_lock.

    Windows has it's own threading library and you'll want to look at either critical sections or CreateMutex. Critical sections are more optimized but are limited to a single process and you can't use them in WaitForMultipleObjects.

提交回复
热议问题