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

Single producer/consumer circular buffer which only blocks consumer

I'd like to implement a buffer with single producer and a single consumer, where only the consumer may be blocked. Important detail here is that the producer can drop the update if the queue is full. I've considered converting a wait-free…
wds
  • 31,873
  • 11
  • 59
  • 84
3
votes
1 answer

How can I interrupt an infinite sigtimedwait?

My program has an event loop disciplined by epoll (for I/O) and condition variables (for other message activity), as well as a worker thread responsible for catching signals (SIGINT, SIGTERM, SIGHUP). SIGINT, SIGTERM, SIGHUP and SIGPIPE are blocked…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
3
votes
1 answer

Print in single Pthread

I'm trying to implement a program using Pthreads in C. Now, I've tried to let a single thread print "Hi": void * generator(void *arguments){ printf("Hi"); return NULL; } int main(int argc, const char* argv[]){ …
Steven
  • 1,123
  • 5
  • 14
  • 31
3
votes
2 answers

PHP pthreads: Thread dosen't executes methods from other objects async

Seems like I have some Coding error here, maybe someone can help me. Example: class test { public function check() { $fp = fsockopen('10.10.5.55','80', $errno, $errstr, 1.5); } } class Main extends Thread { …
Ne00n
  • 67
  • 6
3
votes
1 answer

Cmake failed to find Threads package with cryptic error message

I'm trying to configure with following CMakeLists.txt: cmake_minimum_required(VERSION 3.2) project(MotionBlow CXX) find_package(Threads REQUIRED) …
morynicz
  • 2,322
  • 2
  • 20
  • 34
3
votes
2 answers

C: blocking read should return, if filedescriptor is deleted

I am reading in a blocked way from a device/filedescriptor. It might happen, that in a different thread the device is closed and filedescriptor is deleted. Unfortunatly the read doesn't return or take notice and keeps blocking. As a workaround I…
Arno
  • 257
  • 1
  • 10
3
votes
2 answers

Function pointer typedef in c

I have some embedded OS functions that I need to simulate on a linux machine. The approach I've been instructed to take is to overload the embedded OS functions and wrap them around POSIX threads so the linux machine can handle the embedded OS…
cjameston
  • 199
  • 3
  • 11
3
votes
4 answers

How to forking process in a way such that reaping the child isn't neccessary

I seem to have a vague memory that some facility in Linux exists that allows one to fork() a process in such a way that the child is automatically reaped by the system without a zombie being created. What is this mechanism? Or is my memory just…
Chimera
  • 5,884
  • 7
  • 49
  • 81
3
votes
1 answer

Does a thread own a mutex after pthread_cond_timedwait times out?

After a thread calls pthread_cond_timedwait, and it returns ETIMEDOUT, does the thread own the mutex? I would initially think NO, but it appears that we must call pthread_mutex_unlock even after pthread_cond_timedwait returns ETIMEDOUT. The…
Cinolt Yuklair
  • 397
  • 2
  • 11
3
votes
2 answers

Linux/C: Check if context switch has occurred from inside thread

In a Linux/GNU/C environment, is there any visibility a running thread has into whether it has been put to sleep. For example say you have a function like void foo() { startClock(); bar(); endClock(); } But you're only concerned with the…
user79126
  • 181
  • 1
  • 2
  • 5
3
votes
0 answers

How to fix a segmentation fault when using Symfony's container with pthreads?

I'm using Symfony 3 and php pthreads in my project. I need to access the entity manager from a Thread. I read some way how to do this on StackOverflow and the issue tracker of pthreads. class BaseBackgroundThread extends \Thread { private…
Dm3Ch
  • 621
  • 1
  • 10
  • 26
3
votes
1 answer

Thread not printing out in correct order

I'm fairly new to threads in C. For this program I need to declare a thread which I pass in a for loop thats meant to print out the printfs from the thread. I can't seem to get it to print in correct order. Here's my code: #include…
John Livingston
  • 43
  • 1
  • 11
3
votes
3 answers

Possible Stack Corruption

With reference to my previous question about GDB not pinpointing the SIGSEGV point, My thread code is as follows: void *runner(void *unused) { do { sem_wait(&x); ... if(/*condition 1 check*/) { sem_post(&x); sleep(5); …
user191776
3
votes
3 answers

C Pthreads mutex values?

I am writing a program with a few critical sections. The thing is I need to check the value of a mutex in an if statement. I would like to do something like this: if pthread_mutex(&mutex) == 0 // locked // Do something else if…
user427390
3
votes
1 answer

Using pthread lib in C with Cmake

/* Edited */ my Cmakefile.txt file is: cmake_minimum_required(VERSION 3.3) project(WebServer) set(CMAKE_C_COMPILER "/usr/bin/gcc") set(SOURCE_FILES io.c server.c lock_fcntl.c sig_handler.c thread_job.c msg_parser.c) set(LIB…
Emanuele Vannacci
  • 321
  • 1
  • 6
  • 15