I am using pthread library for multi-threading. Inside thread function, I use sleep system call. Will this block a single thread or the whole process. Thanks.
I am using pthread library for multi-threading. Inside thread function, I use sleep system
Share
Generally,
sleepaffects only the calling thread. Real, kernel-managed threads run independently of each other. In an app that has “green” threads, though (not native to the OS; managed by the app itself), a system call that blocks may block everything. But that kind of brokenness is rather rare — software managing green threads tends to provide a whole runtime environment, including ways tosleepwithout resorting to a system call.The better question is…do you really need to
sleepat all? Time-based synchronization tends to lead to race conditions and fragile apps. There’s a way for threads to wait on and trigger each other; that leads to better determinism.