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

Getting segmentation fault while creating reader and writer threads inside a infinite while loop on random condition

I am trying to create reader and writer threads (5 each) inside an infinite while loop randomly. The writers should wait until all readers are done executing. I am using mutex and condition variables for this purpose. // Global variables int…
3
votes
1 answer

pthread_create fails with EAGAIN after 2 hours of execution

I have a multithread linux application running on a linux system The application has been working successfully in different Linux systems and kernels without never noticing this issue. We are currenlty using this kernel #ulimits -a Linux AM38…
webadm
  • 51
  • 5
3
votes
4 answers

Function which takes a pthread as input and suspends it

I'm trying to port the real time Thread_Metric from ExpressLogic in POSIX, in order to benchmark PREEMPT_RT patches for Linux, Xenomai and RTAI for my thesis. They provide a C source file with the following functions, which you have to implement in…
ody
  • 31
  • 2
3
votes
2 answers

g_atomic_int_get guarantees visibility into another thread?

This is related to this question. rmmh's claim on that question was that on certain architectures, no special magic is needed to implement atomic get and set. Specifically, in this case that g_atomic_int_get(&foo) from glib gets expanded simply to…
laslowh
  • 8,482
  • 5
  • 34
  • 45
3
votes
2 answers

Detect percentage of time main thread is used

I am trying to detect the percentage of time that the Main thread is busy so I can log this metric when a user is using the app. Currently, the closest thing I can find is the user_time from basic_info with the help from an answer here but how can i…
Wazza
  • 1,725
  • 2
  • 17
  • 49
3
votes
2 answers

How to free memory allocated by thread-function in the main

I have allocated heap memory in the thread function f1, this storage is used to calculate the value in the heap region so that the main function can see it. Here is the thread function definition: void *f1(void *input){ int sum =…
Nouman Tajik
  • 433
  • 1
  • 5
  • 18
3
votes
1 answer

How can I send socket id through pthread?

I have a server in a raspberry pi, and want to allow multithreading. The server is working. The client is in windows. I believe I need to send the socket id through the pthread_create, but haven't found how. Is there anything else I need to…
Rui
  • 33
  • 4
3
votes
2 answers

Does sleep() system call have any drawbacks?

So my aim is to execute a piece of code handled by a thread (let's say thread 1 using POSIX threads) while cancelling a different thread (thread 2) executing it's respective task. Thread 1 is initiated when a particular event occurs (time based…
Ayush Das
  • 41
  • 4
3
votes
2 answers

expected expression before ' {' with mutexs initialize

I'm trying to initialize arrays of mutexes and condition variables inside a function. The array is of type Cell which i deifined and each Cell contain mutex, condition variable and char. I'm getting the error on the 3 lines inside the for loop in…
Roy Ancri
  • 119
  • 2
  • 14
3
votes
2 answers

can pthread_cond_signal make more than one thread to wake up?

I'm studying on condition variables of Pthread. When I'm reading the explanation of pthread_cond_signal, I see the following. The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified…
3
votes
3 answers

pthreads - how to parallelize a job

I need to parallelize a simple password cracker, for using it on a n-processor system. My idea is to create n threads and to feed them more and more job as they finish. What is the best way to know when a thread has finished? A mutex? Isn't…
zakk
  • 375
  • 1
  • 4
  • 14
3
votes
2 answers

exiting the program in a multi-threades program

I'm writing a program that uses the POSIX thread library. I'm performing some return value of system calls, such as: if (pthread_join(temp, NULL) != 0) { cerr << "system error\n" << endl; exit(1); } I want the program to exit…
Zach
  • 537
  • 4
  • 9
  • 19
3
votes
3 answers

pthread_cond_wait not waking up from pthread_cond_broadcast

in my program there's a part of code that waits to be waken up from other part of code: Here's the part that goes to sleep: void flush2device(int task_id) { if (pthread_mutex_lock(&id2cvLock) != SUCCESS) { cerr << "system error -…
Zach
  • 537
  • 4
  • 9
  • 19
3
votes
1 answer

Description of the members of struct pthread_rwlock_t

Can somebody please summarize what the different members of the pthread_rwlock_t means? struct { int __lock; unsigned int __nr_readers; unsigned int __readers_wakeup; unsigned int __writer_wakeup; unsigned int…
ashish
  • 813
  • 3
  • 10
  • 18
3
votes
2 answers

Program not exiting after using POSIX timers

Consider the following program: #define _POSIX_C_SOURCE 200809L #include #include #include void timerfunc(union sigval val) { } int main() { struct sigevent sev = { .sigev_notify = SIGEV_THREAD, …
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711