Thread Safety in C

前端 未结 9 2076
余生分开走
余生分开走 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:08

    If your goal is to be compatible on unix-like operating systems, I would use POSIX threading.

    That being said, if you want to support windows as well, you'll need to have two code paths for this - pthreads on unix and Windows threads on Windows. It's fairly easy to just make your own "thread library" to wrap these.

    There are quite a few that do this (like OpenThreads), but most of them I've used are C++, not C.

提交回复
热议问题