Threading in C, cross platform

后端 未结 8 850
情话喂你
情话喂你 2021-02-05 14:40

I am dealing with an existing project (in C) that is currently running on a single thread, and we would like to run on multiple platforms AND have multiple threads. Hopefully, t

8条回答
  •  青春惊慌失措
    2021-02-05 15:22

    I would use the POSIX thread API - pthread. This article has some hints for implementing it on Windows, and a header-file-only download (BSD license):

    http://locklessinc.com/articles/pthreads_on_windows/

    Edit: I used the sourceforge pthreads-win32 project in the past for multi-platform threading and it worked really nicely. Things have moved on since then and the above link seems more up-to-date, though I haven't tried it. This answer assumes of course that pthreads are available on your non-Windows targets (for Mac / Linux I should think they are, probably even embedded)

提交回复
热议问题