Questions tagged [pthreads]
9 questions
2
votes
0 answers
multithreading - waiting on a condition without using locks (c++11)
i've been wondering about it for a while now but never found any answers. is it possible to use something like a condition variable without a lock?
I have a vector of objects, and a thread pool, and I want each thread to access a specific cell once…
2
votes
3 answers
C Thread Architecture
I'm trying my hand at multi-thread C programming and decided to start with a simple ncurses program to move a character across the terminal screen and change direction based on user input (think classic snake game). I decided that I needed to…
bgregs
- 167
1
vote
2 answers
How to handle errors of pthreads fundamental lock und unlock functions?
I am writing a little C library for the Raspberry Pi for controlling 433MHz transmitters/receivers. While receiving data the whole application would block, so I decided to put this code into a separate thread and synchronize it with the main…
blackdog
- 21
1
vote
4 answers
Best algorithm to multi-thread this application?
I define an algorithm to be best if it minimizes the total run time over commodity hardware (e.g. normal desktop and server PCs).
I have sets A and B. I also have function f that works like f(a, b, n), where a is some item in A, b is some item in B,…
caveman
- 73
0
votes
1 answer
An adaptor layer for Pthread, C11, and C++11 threads compatibility
As my next spare-time project, I'm considering writing a suite of compatibility header and associated library, that eases the transition from Single Unix Specification v4 to v5 and C11/C17 to C2X. C++ will not be my concern, but it adds to the…
DannyNiu
- 372
0
votes
0 answers
What is the difference between pthread scope vs. policy?
I'm reading OS Concepts for my undergrad OS class and came across this topic: Pthread scheduling (System and Process)
Then I kept reading and came across POSIX Real-Time Scheduling that has two scheduling classes:
SCHED_FIFO: first come first…
mLstudent33
- 101
0
votes
2 answers
pattern to unlock thread and get variable in fast unlock
I have a thread that goes in a loop doing something like this
void thread()
{
pthread_mutex_lock(mutex);
for ( ; ; )
{
/** code **/
{
pthread_mutex_unlock(mutex);
/** do_something **/
pthread_mutex_lock(mutex);
…
cauchi
- 1,222
0
votes
0 answers
using pthread_cond_broadcast with no mutex or waiting thread?
Assuming some pthread_cond_t condvar; properly initialized with pthread_cond_init am I allowed to pthread_cond_broadcast it without any mutex locked and thread blocked with pthread_cond_timedwait on it?
I tend to understand that it is possible (with…
Basile Starynkevitch
- 32,862
-2
votes
1 answer
How should functions that keep state across multiple invocations be made safe?
In Computer Systems: a Programmer's Perspective,
12.7.1 Thread Safety
When we program with threads, we must be careful to write functions
that have a property called thread safety. A function is said to be
thread-safe if and only if it will always…
Tim
- 5,545