Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pthread sleep linux

I am creating a program with multiple threads using pthreads.

Is sleep() causing the process (all the threads) to stop executing or just the thread where I am calling sleep?

like image 843
Steveng Avatar asked Sep 03 '10 04:09

Steveng


People also ask

What is sleeping threads in Linux?

When a thread is called the sleep method, the thread will be added into a sleep queue. If the compute clock frequency is 100HZ, that means every 10ms the current running process will be interrupted. After reserve the current context of the thread, then it will decrease the value (-10ms) for each thread.

What is sleep () in C?

Return Value The sleep() function in C returns 0 if the requested time has elapsed. Due to signal transmission sleep() returns the unslept quantity, a difference between the requested time to sleep() and the time it actually slept in seconds.

How do you wake up a thread?

We can wake the thread by calling either the notify() or notifyAll() methods on the monitor that is being waited on. Use notifyAll() instead of notify() when you want to wake all threads that are in the waiting state.

How does pthread work in Linux?

Pthread uses sys_clone() to create new threads, which the kernel sees as a new task that happens to share many data structures with other threads. To do synchronization, pthread relies heavily on futexes in the kernel.


1 Answers

Just the thread. The POSIX documentation for sleep() says:

The sleep() function shall cause the calling thread to be suspended from execution...

like image 85
caf Avatar answered Sep 20 '22 20:09

caf