Questions tagged [pthreads-win32]

pthreads-win32 provides an implementation of pthreads for Win32.

pthread-win32 - The POSIX 1003.1-2001 standard defines an application programming interface (API) for writing multithreaded applications. This interface is known more commonly as pthreads. A good number of modern operating systems include a threading library of some kind: Solaris (UI) threads, Win32 threads, DCE threads, DECthreads, or any of the draft revisions of the pthreads standard. The trend is that most of these systems are slowly adopting the pthreads standard API, with application developers following suit to reduce porting woes.

Win32 does not, and is unlikely to ever, support pthreads natively. This project seeks to provide a freely available and high-quality solution to this problem.

Various individuals have been working on independent implementations of this well-documented and standardised threading API, but most of them never see the light of day. The tendency is for people to only implement what they personally need, and that usually does not help others. This project attempts to consolidate these implementations into one implementation of pthreads for Win32.

Level of standards conformance

Pthreads-win32 currently implements a large subset of the POSIX standard threads related API. See our conformance page for a complete list of options and functions implemented as well as those that aren't.

HTML formatted manual pages are now available inside the package and on this site. Peruse them for additional Pthreads-win32 information.

How does it work?

The Win32 pthreads is normally implemented as a dynamic link library (DLL). This has some notable advantages from the Win32 point of view, but it also more closely models existing pthread libraries on UNIX which are usually shared objects (e.g. libpthread.so). Please note though, that the library can also be built for static linking if necessary.

Official Website: http://www.sourceware.org/pthreads-win32/

Useful Linkes:

52 questions
2
votes
2 answers

Why main thread is slower than worker thread in pthread-win32?

void* worker(void*) { int clk = clock(); float val = 0; for(int i = 0; i != 100000000; ++i) { val += sin(i); } printf("val: %f\n", val); printf("worker: %d ms\n", clock() - clk); return 0; } int main() { …
Lei He
  • 29
  • 3
2
votes
1 answer

pthread_cond_timedwait returns error 138

I can't find any information on this with Google, so I post here hoping that someone can help... My problem is with the Windows pthread function pthread_cond_timedwait(). When the indicated time is elapsed, the function should return with value…
Rusty Gear
  • 455
  • 1
  • 4
  • 11
1
vote
1 answer

Thread job not totally completing

I've never really done much with multithreading until recently (Vulkan), so I'm not well versed in it. I have a small test program here: https://github.com/seishuku/ThreadPool_TEST It should just run the 4 jobs in parallel, then when all are done,…
Seishuku
  • 83
  • 5
1
vote
1 answer

setting CPU affinity error on windows pthread_setaffinity_np

I have a multithread project. I want to set CPU affinity to particular thread. I am working on Windows and using MinGW compiler. but when i initialize type cpu_set_t, i have an error "type cpu_set_t was not declared in this scope". I dont understand…
reesu
  • 26
  • 4
1
vote
1 answer

Cross compile modern C++ from Linux to Windows

I have some modern C++ sources (C++17, say) and I have no problem compiling complex source base on Linux for Linux 32/64, and on Windows for Windows 32/64 using mingw-w64 (from msys2). Now I want to cross compile for Windows on Linux, to avoid using…
Leandro
  • 195
  • 3
  • 11
1
vote
0 answers

sem_timedwait() pthreads-win32 errno usage

I am using pthreads-win32 for threads on a Win32 Application. I am calculating the timespec using the first function posted here. The call to sem_timedwait() appears to be waiting for the specified ts time, however every time it completes I get the…
1
vote
0 answers

pthread_setcanceltype workaround in android

I am writing code for my first tool which supports multi threading but also I want to make my tool for both Linux & Android , and pthread_cancel can't be used in android so I am trying to make separate header file universal-threading.h in which I…
Golu
  • 350
  • 2
  • 14
1
vote
1 answer

Cancelling a thread in pthread_cond_wait yields to access violation under MinGW

My program dies with an access violation in Windows (Windows 7 - 32 bits). It is C code compiled with gcc 4.8.1 under MinGW. It uses pthreads-w32 2.9.1. There are several threads working concurrently with no other apparent issues. It can run well…
Emilio Perez
  • 316
  • 3
  • 10
1
vote
1 answer

PHP: Pthread + Memcache trouble

Memcache doesn't seem to work inside a pthread thread. I get this warning: Warning: Memcache::get(): No servers added to memcache connection in test.php on line 15 class Test extends Thread { protected $memcache; function…
nullException
  • 1,112
  • 4
  • 17
  • 29
0
votes
0 answers

How do I install pthreads-w32 statically in a project built using configure.js and nmake?

I am building PHP from source code using the Visual C++ 2017 compiler, and it uses configure (configure.js) to configure the build, and nmake to build. I've read the documentation on pthreads-w32 (nonportable) and read a lot of answers here, but it…
Antinet
  • 1
  • 2
0
votes
0 answers

Heap corruption with pthreads in C

I've been writing a C program to simulate the motion of n bodies under the influence of gravity. I have a working version that uses a single thread, and I'm attempting to write a version that uses multi-threading with the POSIX pthreads library.…
0
votes
0 answers

How can I let CMake find an external package?

I tried to build Qv2ray with CMake and Visual Studio on Windows and got the error: CMake Error at cmake/backend.cmake:9 (message): gRPC Not Found Call Stack (most recent call first): CMakeLists.txt:257 (include) Check…
peter
  • 379
  • 2
  • 6
  • 16
0
votes
0 answers

How to install and setup pthread library in dev -c++

I am a student and new to multithreading concepts. By default, the compiler does not have pthread.h header file required for it. I have searched a lot but I was unable to find the correct method to set up pthread.h header file in my compiler. The…
M.Jafar
  • 17
  • 5
0
votes
1 answer

Why is `pthread_testcancel` called multiple times in the `nanosleep` implementation of winpthreads?

The nanosleep implementation of winpthreads, which is a port of POSIX threads to Windows, calls pthread_testcancel multiple times in its implementation. nanosleep in [nanosleep.c] calls pthread_delay_np_ms which is not exported and does the actual…
xiver77
  • 2,162
  • 1
  • 2
  • 12
0
votes
2 answers

must to use pthread library to compile multithreaded programs in MinGW environment?

must to use pthread library to compile multithreaded programs in MinGW environment? I saw that the header file declared the _ beginthreadex function in the integrated MinGW, in TrueStudio. but there was an exception in the operation of the program.…
anti-gravity
  • 122
  • 6