Alex Rivera | Logout

Threading in C, cross platform

Asked 2011-04-10T17:57:47.460
17

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, there is a library for this, because, IMHO, the Win32 API is like poking yourself in the eye repeatedly. I know about Boost.Thread for C++, but, this must be C (and compilable on MinGW and gcc). Cygwin is not an option, sorry.

Edit
Report

1 Answer

2

Given that you are constrained with C. I have two suggestions:

1) I have a seen a project (similar to yours) that had to run on Windows and Linux with threads. The way it was written was that it (the same codebase) used pthreads on Linux and win32 threads on Windows. This was achieved by a conditional #ifdef statement wherever threads needed to be created such as

#ifdef WIN32

//use win32 threads

#else

//use pthreads

#endif

2) The second suggestion might be to use OpenMP. Have you considered OpenMP at all?

Please let me know if I missed something or if you want more details. I am happy to help.

Best, Krishna

answered 2011-04-10T18:33:51.917

Your Answer