C: Multithreading

2020-02-10 07:12发布

Is multithreading supported in C? If yes, then how do I try? Is there any open source library that lets me do it and is the library supported on Mac OS X?

I haven't found any article saying that it's supported.

5条回答
2楼-- · 2020-02-10 07:58

C is not intrinsically a multithreaded language; however there are many libraries which add threading functionality.

查看更多
戒情不戒烟
3楼-- · 2020-02-10 08:05

the new dialect - C1X, will offer multi-threading out of the box, as stated from wikipedia:

Multithreading support (_Thread_local storage-class specifier, header including thread creation/management functions, mutex, condition variable and thread-specific storage functionality, as well as the _Atomic type qualifier and for uninterruptible object access).

currently of courae as mentioned above, multi-threading is not supported in the newest dialect of c - C99

查看更多
唯我独甜
4楼-- · 2020-02-10 08:06

I would guess that the majority of multithreaded programming on Mac OS X is done in Objective-C or C++, not plain C. (I realize that this isn't exactly an answer to the question that you asked, but you might want to know about alternatives.) In Objective-C, you'd use NSThread or, in Snow Leopard and later, Grand Central Dispatch (GCD). In C++, you could use the threads library from boost.org, which has the advantage of being cross-platform.

查看更多
够拽才男人
5楼-- · 2020-02-10 08:17

Pthreads. OSX has posix support.

查看更多
霸刀☆藐视天下
6楼-- · 2020-02-10 08:18

C has no concept whatever of threads. There is no thread support in C Standard. There are extensions available that can implement multi threading - one of which is pthreads.

Be aware because C language has no natural support of threads you as the programmer have to take care of everything and you will not be protected against any of the pitfalls of multi-threaded programming.

查看更多
登录 后发表回答