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

Does pthread_cond_signal function unlock the mutex the calling thread locked?

When i call 'pthread_cond_signal' during my thread's function, does this call unlock the mutex i currently use? (Not the one the pthread_cond_wait is waiting for).
Zach
  • 537
  • 4
  • 9
  • 19
3
votes
3 answers

Why the pthread_join is giving this error? [Error] invalid conversion from 'void*' to 'void**' [-fpermissive]

I'm following this application by my book, and I tried to copy this program and see what it does. With my big surprise I found that it doesn't work!! The program is the following: #include #include #include #include…
3
votes
1 answer

How to manage properly pthread

I have some random issues sometimes to join pthread. I can just say that the thread is not stuck in a deadlock with a mutex when the join is failing. Most of the time the thread is idle (sleep syscall) when the timeout occurred on join. My need is…
ArthurLambert
  • 749
  • 1
  • 7
  • 30
3
votes
3 answers

Is it a good practice to call pthread_sigmask in a thread created by std::thread?

1) I'm new to std::thread and I would like to know whether it is a good practice to call pthread_sigmask() to block some signals in a particular thread created by std::thread. I don't want the new thread to receive signals such as SIGTERM, SIGHUP,…
void
  • 338
  • 5
  • 19
3
votes
1 answer

What is the problem for PTHREAD_CANCELED and thread’s start function return value

I'm reading Kerrisk's book and see that the following as a note, Caution is required when using a cast integer as the return value of a thread’s start function. The reason for this is that PTHREAD_CANCELED, the value returned when a thread is…
3
votes
1 answer

Reading stdin from another thread

I am using p_threads in my code on unix. In my main program I have a thread Node which makes 2 threads one of which is doing a read from the standard input using getline. All of this working fine. Except at some point during my code I have to…
Teotia
  • 45
  • 1
  • 6
3
votes
2 answers

What does exactly the "status" in pthread_join represent and how to query it

I'm wondering what exactly the "status" parameter in the pthread_join is for int pthread_join(pthread_t thread, void **status); I'm trying to make use of it but I cannot understand what exactly does it represent. According to the…
celavek
  • 5,575
  • 6
  • 41
  • 69
3
votes
2 answers

Error : LNK1104 cannot open file 'pthread.lib'

I am trying to compile a native Linux C++ application in Windows using Visual Studio 2017. The app uses WebRtc's Acoustic Echo Cancellation(AEC) APIs to negate echo on wav files. Following is the CmakeLists.txt file: cmake_minimum_required(VERSION…
Kazi Hasan
  • 275
  • 1
  • 4
  • 9
3
votes
1 answer

How to assign threads to different cores in C?

I created a program that does the addition of 8 numbers using 4 threads, and then the product of the results. How to ensure that each thread is using a separate core for maximum performance gains. I am new to pthreads so I really don't have any idea…
3
votes
3 answers

Reusing a thread - boost vs std thread behaviour

I seem to be getting different thread object assignment behaviour between boost and std threads. If I use boost threads, a thread member variable can be reassigned and the thread recreated. If I use std threads, I get a runtime error terminate…
aleksk
  • 661
  • 7
  • 15
3
votes
3 answers

C double buffer implementation deadlock?

I am creating a threaded application that uses double buffering and I am trying to avoid a potential deadlock. The main idea is that the swap buffer thread locks out the write and the read thread. However the swap buffer thread is fast so the…
eat_a_lemon
  • 3,158
  • 11
  • 34
  • 50
3
votes
2 answers

Why does a redundant extra scoping block affect std::lock_guard behaviour?

This code demonstrates that the mutex is being shared between two threads, but something weird is going on with the scoping block around thread_mutex. (I have a variation of this code in another question, but this seems like a second…
spraff
  • 32,570
  • 22
  • 121
  • 229
3
votes
2 answers

Why is std::mutex taking a long, highly irregular amount of time to be shared?

This code demonstrates that the mutex is being shared between two threads, but one thread has it nearly all of the time. #include #include #include #include int main () { std::mutex m; std::thread t…
spraff
  • 32,570
  • 22
  • 121
  • 229
3
votes
2 answers

Memory leaks and pointers

I have implemented a program which adds up the elements of an array using threads. Each thread adds the elements of a portion of the array and puts it inside an array. Finally, another thread sums those up. This programs seems to work, BUT I have…
CyberFox
  • 342
  • 3
  • 16
3
votes
2 answers

pthreads signal a specific thread

In pthreads, is it possible for a thread to wake up another thread given only the other thread's id? (Kind of like, calling pthread_cond_signal() but with also a specific, known, thread id in mind)
ManRow
  • 1,563
  • 4
  • 21
  • 40