Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pthread.h on a windows build

Tags:

c++

c

pthreads

I have a codebase that makes extensive use of pthread.h. On a windows visual studio project, this obviously doesn't work since pthreads is a unix utility.

I know there exists pthread-win32 or something of the sort, but is there a way to have a codebase use this, without replacing all of the pthread code?

edit: I'd prefer to not have to go through and replace all the pthread calls. This is my question

like image 779
oldspice Avatar asked Nov 12 '10 23:11

oldspice


People also ask

Can pthread be used in Windows?

Windows does not support the pthreads standard natively, therefore the Pthreads4w project seeks to provide a portable and open-source wrapper implementation. It can also be used to port Unix software (which uses pthreads) with little or no modification to the Windows platform.

How do I use pthread h in Visual Studio?

If the pthread. h file still can't be found by VS, you can try to include it manually, for example right-click your project > Properties… > Configuration Properties > VC++ Directories > Reference Directories > Edit > add a new line(path) which points to the folder that includes the pthread.

Does MinGW support pthread?

The MinGW has already support POSIX threads, In the "MinGW Installation Manager", we can install the pthreads dev package and pthreads lib.


1 Answers

Try http://sourceware.org/pthreads-win32/. While I've never used that particular library, I've had luck using some windows ports/abstraction layers of POSIX APIs.

like image 57
Novikov Avatar answered Sep 23 '22 08:09

Novikov