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

What is the C way to report progress of computation?

This is a follow-up question to Using a thread in C++ to report progress of computations. Suppose that I have a for loop which executes run_difficult_task() many times, and I would like to infer how far the loop has advanced. I used to write: int…
Matsmath
  • 1,164
  • 2
  • 21
  • 40
3
votes
3 answers

C: pthread performance woes. How can I make this code perform as expected?

I have created this little program to calculate pi using probability and ratios. In order to make it run faster I decided to give multithreading with pthreads a shot. Unfortunately, even after doing much searching around I was unable to solve the…
kellpossible
  • 663
  • 1
  • 8
  • 19
3
votes
1 answer

Detect deadline thread preemption

I'm implementing a thread using SCHED_DEADLINE scheduling policy which is my high-priority thread and another one using SCHED_FIFO policy which is my low-priority one. As an example, I've defined my deadline thread as follow : attr.sched_runtime =…
c.censier
  • 781
  • 7
  • 23
3
votes
2 answers

invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-fpermissive]

I've been working on this program all day and I can't get my errors to work out. I've searched all over the internet for a sufficient answer but I am not sure what I am doing wrong. I've tried everything I could think of to get these errors out of…
dennarai
  • 41
  • 1
  • 4
3
votes
2 answers

How to run short asynchronous tasks efficiently under Linux?

I'm trying to meet a soft real-time requirement where a task needs to complete in < 1 ms under Linux. Currently I'm using pthreads with 4 - 8 threads to try and achieve this, but it seems that the overheads and latencies with pthreads under Linux…
Paul R
  • 208,748
  • 37
  • 389
  • 560
3
votes
1 answer

Single reader multiple writers with pthreads and locks and without boost

Consider the next piece of code. #include #include #include using namespace std; map> map_vec; vector> how_much_and_where; pthread_cond_t CV =…
Alex Goft
  • 1,114
  • 1
  • 11
  • 23
3
votes
3 answers

why does thread procedure should be static or member function

why does thread procedure should be static or member function? any valid reason?
Naruto
  • 9,476
  • 37
  • 118
  • 201
3
votes
1 answer

Killing Threads with pthreads - C

I have a C pthread program that creates N threads in main that update a global variable. Main also calls pthread_join on all of these update threads to wait for them to finish. I also have 2 watcher threads that use pthread condition variables to…
Dylan
  • 89
  • 4
3
votes
1 answer

Does atexit wait for other threads to die?

Are the functions registered with atexit() the last functions to be executed? Is it possible that other threads at this time are still running?
今天春天
  • 941
  • 1
  • 13
  • 27
3
votes
1 answer

error: invalid conversion from ‘int (*)(void*)’ to ‘void* (*)(void*)’

I amtrying to spawn pthreads and send an integer as the argument but I am getting the following error when casting the argument to void. I tried to remove (void*) and make the conversion implicit but I still got the same error error: invalid…
user3043108
  • 965
  • 1
  • 8
  • 10
3
votes
2 answers

Unable to properly free allocated memory on heap, detected by Valgrind

I am have an issue with freeing my allocated memory, and it seems that my inexperience has lead me to this fatal error. Below I have a simple code: #include #include #include void *thread(void *arg) { return…
Belphegor
  • 1,683
  • 4
  • 23
  • 44
3
votes
1 answer

czmq multiples zactor instances crash

I'm trying to write a basic example using zhash and zactor from the czmq library. The main idea of what I'm trying to achieve is: Create 1024 zactor instances and send "START" command after each actor creation. Wait for response from the actor to…
svdev
  • 33
  • 1
  • 3
3
votes
1 answer

Segfault in pthread_join

I have a fairly simple C code: #include #include #include void* run(void *arg) { printf("hello from %d!\n", *(int*)arg); pthread_exit(NULL); } int main() { int ids[4]; pthread_t threads[4]; for (int i =…
lennoff
  • 302
  • 4
  • 9
3
votes
4 answers

Concurrent access to a large collection of items

I'm working on a simulation project using c++ on both windows and linux. There will be several thousand objects (Perhaps 3000-5000) in the simulation. In plan to have several threads performing actions on the objects so that it makes good use of…
jcoder
  • 29,554
  • 19
  • 87
  • 130
3
votes
1 answer

no reference to pthread_mutex_lock with -lpthread compiled

I am compiling a program that contains mutex semaphores from the pthread library but when i compile using the -lpthread flag I am getting an undefined reference error. gcc -lpthread prodcon.c /tmp/ccESOlOn.o: In function…
aastorms
  • 45
  • 1
  • 1
  • 4
1 2 3
99
100