Questions tagged [pthreads]

Pthreads (POSIX Threads) is a standardised C-based API for creating and manipulating threads. It is currently defined by POSIX.1-2008 (IEEE Std 1003.1, 2013 Edition / The Open Group Base Specifications Issue 7).

The API is mostly covered by the header documented at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html and the behaviour by http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09

See https://en.wikipedia.org/wiki/POSIX_Threads for more details and further reading. The POSIX.1-2008 Base Definitions is available online at http://pubs.opengroup.org/onlinepubs/9699919799/

POSIX Threads is also covered extensively in Programming with POSIX Threads by David Butenhof.

A port to MS-Windows (x86/x64) is available at: https://sourceware.org/pthreads-win32/

pthreads is also the name of an Object Oriented API that allows user-land multi-threading in PHP created by Joe Watkins

8869 questions
3
votes
1 answer

Handling GUI thread in a program using OpenMP

I have a C++ program that performs some lengthy computation in parallel using OpenMP. Now that program also has to respond to user input and update some graphics. So far I've been starting my computations from the main / GUI thread, carefully…
ASD1
  • 31
  • 2
3
votes
2 answers

Merge Sort with PThreads in C

Side Note: I'm beginning to learn how to use pthreads and I'm starting to get the concept. I've been using this example script (written in C++) here to manage a Merge Sort with threads:…
theflarenet
  • 642
  • 2
  • 13
  • 27
3
votes
3 answers

pthread_kill() vs pthread_cancel() to terminate a thread blocked for I/O

In our server code we are using poll() system call for monitoring client sockets. The poll() is called with a large timeout value. So the thread calling poll() gets blocked for I/O. As per the flow, we have a scenario where we need to terminate…
3
votes
1 answer

Why does pthread_create() sometimes give EAGAIN on Cygwin port?

What does it mean when pthread_create() returns errno 11 (EAGAIN), "Resource temporarily unavailable"? I am porting my application to Cygwin from it working great on Centos 4. Every once in a while, the application fails in its call to…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
3
votes
1 answer

C++ callback timer implementation

I have found the following implementation for a callback timer to use in my c++ application. However, this implementation requires me to "join" the thread from the start caller, which effectively blocks the caller of the start function. What I…
Dillon
  • 364
  • 5
  • 18
3
votes
1 answer

aborting a blocking read on linux

I have a blocking read in linux running in a thread. During program shutdown I want to break the thread out of this read. Unfortunately I can't use poll or select and write proper code because the file that is read from is a device driver that does…
Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
3
votes
3 answers

Why does my client kill my server?

How come when a thread exits the parent process also exits? When I run the server all is well. It sits and listens on the socket. When a client connects the server threads to serve it. When they talk back and forth the client exits and the…
KeatsKelleher
  • 10,015
  • 4
  • 45
  • 52
3
votes
1 answer

CBMC detected an assert error in my Pthreads program, is it correct?

I use CBMC to verify my Pthreads program, it detected some assert errors which I don't think would exist. The error only occur when I run the two threads at the same time. That is to say, when I put one of the statement which calls the thread…
Bailin Lu
  • 73
  • 7
3
votes
0 answers

When and how is cancellation point checked?

I understand that when reaching cancellation point it's checked whether request to cancel thread was made or not. In my code the request is made AFTER thread enters sleep(1000) call. So can anyone explain exactly when is cancellation status checked…
3
votes
1 answer

BOOST threads: threads or processes?

Are BOOST threads (around version 1.49) real threads or separate processes? When I had run a precompiled version of a docking tool, it looked like several processes (with different process IDs and 100% CPU usage each) using top, but when I compiled…
Amr ALHOSSARY
  • 196
  • 1
  • 14
3
votes
1 answer

How is the POSIX threading api versioned and has it been updated since 1995?

I'm just now getting into threading and specifically I want to learn POSIX threads, and everything about them. As implemented in Linux. I'm looking for resources to learn about them but many of those resources are very old. Some of them date back to…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
3
votes
1 answer

Why does pthread_cond_wait() not block when not linked with "-lpthread"?

I'm learning about pthread_cond_t and wrote the following code intended to block forever at the pthread_cond_wait(): // main.cpp // Intentionally blocks forever. #include #include #include #include int…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
3
votes
2 answers

What happens to the thread spawned by a shared library, upon dlclose

This is the scenario: I have an application (main.exe) which dynamically loads a library libA.so using dlopen(). libA.so has dependency on another library libB.so. Now libB.so has a constructor that spawns a thread (in detached state) and blocks…
3
votes
1 answer

pthread_cond_timedwait() in Windows

I try to implement pthread functionality in my code. Unfortunately, I am not be able to implement correctly function pthread_cond_timedwait(). In Linux everything works fine. But in Windows this function always returns error code 10060. Here is my…
Vlad
  • 31
  • 4
3
votes
1 answer

Why do pthread_mutex_lock() and pthread_mutex_unlock() contain memory barriers if the function calls themselves act as memory barriers?

I have read that both pthread_mutex_lock() and pthread_mutex_unlock() contain memory barriers. And I also read that when you call a function, the function call itself act as a memory barrier. So what is the point of including memory barriers in the…
James
  • 703
  • 8
  • 17