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
2 answers

How does the function pthread_yield work?

I am implementing a threads library in C and I am stuck on the meaning of pthread_yield(). I have looked it up on the man page in the terminal but I did not really understand the explanation. Could someone explain it to me?
Pete97
  • 81
  • 1
  • 2
  • 6
3
votes
1 answer

Does pthread_cond_wait and pthread_mutex_unlock conflict?

I am implementing manual reset event using pthread in Linux which is similar to WaitForSingleEvent in Windows. I found this post pthread-like windows manual-reset event and follow it, however there a thing that confuse me: void mrevent_wait(struct…
longbkit
  • 1,218
  • 1
  • 13
  • 20
3
votes
3 answers

Multithreading

I have just started learning multi-threading. I have written a simple application. The application creates three threads. Two threads write and one thread reads. The writer threads write to separate location in a global array. The writer thread…
PlugGulp
  • 31
  • 1
3
votes
2 answers

Declaring array in pthreads start_routine function causing segmentation fault

#include #include void* function(void* arg){ int picture[4096][4096]; } int main(){ int N=10, S=10; pthread_t pids[10]; pthread_create(&pids[0], NULL, function, NULL); pthread_join(pids[0], NULL); return 0; } I…
Amit wadhwa
  • 31
  • 1
  • 5
3
votes
4 answers

What happens to a thread that got woken up by pthread_cond_signal() but lost competition for a mutex

Regarding this: How To Use Condition Variable Say we have number of consumer threads that execute such code (copied from the referenced page): while (TRUE) { s = pthread_mutex_lock(&mtx); while (avail == 0) { /* Wait for something to…
racic
  • 1,235
  • 11
  • 20
3
votes
2 answers

libpthread in mingw does not find the libraries

I am trying to compile the following program with mingw: #include #include #include #include #include void *hello(void *id) { int nid = *static_cast(id); std::printf("Hello from thread…
Sambatyon
  • 3,316
  • 10
  • 48
  • 65
3
votes
1 answer

FastCGI fork in c

I'm currently developing highload project, i need to use C/FastCGI/nginx combination. The problem is, i need my FastCGI application to run in threads/processes. I know two ways to do that: 1) Compile program and than use spawn-fcgi to fork…
artyomboyko
  • 2,781
  • 5
  • 40
  • 54
3
votes
2 answers

Finding out statuses of active threads from the current thread. (Implementation of Robust Mutexes)

We are trying to port some code from Solaris to HPUX. While Solaris uses it's own thread API, HPUX uses the Pthread API. One problem that we faced during migration is that Robust mutexes are not being implemented on HPUX, since it was not required…
Aditya
  • 47
  • 1
  • 7
3
votes
2 answers

How can the thread be closed (pthread library)?

I have some code, roughly: pthread_create(thread_timeout, NULL, handleTimeOut, NULL); void handleTimeOut() { /*...*/ pthread_cancel(thread_timeout); /*...*/ } But as I noticed by pthread's manual the cancellation must be used by another…
Rorschach
  • 31
  • 1
  • 2
3
votes
2 answers

pthreads - Stop the current execution of threads and restart them after a specific event

I am doing a project on VoIP and I have got pthreads in my C code. I need to start the pthreads and make them work with some sleep in between them. Right now my threads are running and when I get a session end from the server I need to stop the…
125369
  • 3,547
  • 20
  • 52
  • 70
3
votes
2 answers

Is it possible to use pthreads without pthread_join()?

What I've noticed recently in attempting to add some multithreaded functionality to some code of mine for a project at work is that pthreads are a huge pain in the ass to deal with logistically... Here's the scenario... I have an infinite loop in my…
Rob Toth
  • 33
  • 1
  • 3
3
votes
1 answer

Problem with passing struct pointer by pthread_create

In the code below, when I print f->msg in the main function, the data prints out correctly. However, if I pass the mystruct *f in pthread_create and try to print out the msg value, I get a segmentation fault on the second line of the receive_data…
user482594
  • 16,878
  • 21
  • 72
  • 108
3
votes
2 answers

Using SIGUSR1 and SIGUSR2 as signals in pthread_kill()

I would like to use SIGUSR1 and SIGUSR2 as arguments to pthread_kill() to suspend the execution of the running thread(i.e thread sends signal to itself) and resuming a suspended thread by a peer thread when a condition is met. Would be gratefull…
Lipika Deka
  • 3,774
  • 6
  • 43
  • 56
3
votes
1 answer
3
votes
1 answer

is glibc c11 thread implementation a wrapper on top of pthread?

to build a c11 thread program with glibc I still need link with -lpthread,why? glibc 2.28 claims c11 thread support but why I need pthread still? musl can build c11 thread without pthread though.
Shawn Shaw
  • 181
  • 3
  • 8