简体   繁体   English

Linux:是否从一个线程调用wait()会导致所有其他线程也进入睡眠状态?

[英]Linux: Whether calling wait() from one thread will cause all other threads also to go to sleep?

"The wait() system call suspends execution of the current process until one of its children terminates" . “ wait()系统调用将暂停当前进程的执行,直到其子进程之一终止为止”。 Waitpid also is similar. Waitpid也与此类似。

My Question is whether calling wait() from one thread will cause all other threads (in the same process) also to go to sleep ? 我的问题是从一个线程调用wait()是否会导致所有其他线程(在同一进程中)也进入睡眠状态? Do the behavior is same for detached threads also? 分离线程的行为也一样吗?

This is just a bug in the manual. 这只是手册中的错误。 wait suspends the calling thread, not the process. wait挂起调用线程,而不挂起进程。 There is absolutely no way to suspend the whole process short of sending it SIGSTOP or manually suspending each thread one at a time. 除了发送SIGSTOP或一次手动挂起每个线程外,绝对没有办法挂起整个进程。

As far as I know, calling wait from any thread will cause all threads which are associated with that process to halt. 据我所知,从任何线程调用wait都会导致与该进程关联的所有线程停止。

But don't hold me to that. 但是不要拘束我。 Best thing to do would be to test it. 最好的办法是对其进行测试。

Should only stop the current thread. 应该只停止当前线程。 If you want to make people ill when they look at your code and cause yourself a lot of problems you can use this for jury rigged thread synchronization. 如果您想让人们在查看您的代码时感到不适,并给自己造成很多问题,可以将其用于陪审团操纵的线程同步。 I wouldn't reccommend it though. 我不推荐它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM