Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up pthreads on windows?

I found an implementation for pthreads on Windows here, but I couldn't get it to work right. Can anyone help me to install pthreads ? Like where to put DLLs, .lib, and .h files?

Also, as an environment I'm not using Visual Studio, but Codeblocks with Mingw.

I usually develop on Linux, but this project has to be on Windows, and I've already got some code implemented using pthreads, so I don't want to use Windows Threads from 'windows.h'.

like image 344
tmeloliveira Avatar asked Oct 19 '13 15:10

tmeloliveira


3 Answers

The .dll can go in any directory listed in your PATH environment variable.

The .lib file can go in any directory listed in your LIB environment variable.

The .h files can go in any directory listed in your INCLUDE environment variable.

Also see the FAQs page of the link you shared .

Read Q6, Q7, Q8.

like image 145
Siddhartha Ghosh Avatar answered Oct 17 '22 00:10

Siddhartha Ghosh


For Visual C++ Users (not MingW), follow this steps:

1) download "ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip"

2) in the extraction folder, open the subfolder "Pre-built.2" and you should see the following files:

  • "Pre-built.2\dll\x64\pthreadVC2.dll" OR "Pre-built.2\dll\x86\pthreadVC2.dll"
  • "Pre-built.2\lib\x64\pthreadVC2.lib" OR "Pre-built.2\lib\x86\pthreadVC2.lib"
  • "Pre-built.2\include\pthread.h"
  • "Pre-built.2\include\sched.h"
  • "Pre-built.2\include\semaphore.h"

3) For Visual Studio C++ x64 projects, go to project properties and add the following paths accordingly:

  • Additional lib Files add "yourpath\Pre-built.2\lib\x64\"
  • Additional dll files add "yourpath\Pre-built.2\dll\x64\"
  • Additional include files add "yourpath\Pre-built.2\include\"

Choose the correct files according to your project build (x64 or x86).

like image 25
winux Avatar answered Oct 17 '22 02:10

winux


To install gcc on MSYS2 on Windows:

yes | pacman -Syu gcc

That's it!

By installing gcc on MSYS2, you automatically get pthreads as well.

Here is an example that demonstrates pthreads on MSYS2 (& Linux).

In short - the exact same code as on Linux works fine if you compile and run it inside an MSYS2 terminal. (Not necessarily always true, but true for the example in the link.)

References

like image 28
Henke Avatar answered Sep 27 '22 22:09

Henke