暂停/恢复另一个线程
我知道互斥体可以是一种实现,但是我想知道是否有一种方法可以在视频播放中暂停/恢复另一个线程。当其他正在运行的线程很复杂时,这种方法更容易编程。
I know mutex can be an implementation, however I'm wondering there would be a way to pause/resume another thread as in video-playback. This approach is easier to program when the other running thread is complex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有 SIGTSTP,用于暂停进程的信号,如果您有两个进程,则可以使用它,但信号有几个缺点,因此我不建议使用它们。对于受控的、稳定的方法,您必须使用互斥体自己执行此操作,其中用户暂停播放会导致锁定互斥体,并且执行播放的线程会尝试锁定互斥体。像这样:
如果您需要两个线程之间进行更多通信,您可以使用标准 IPC 机制(例如管道) - 然后您可以基于此实现暂停和恢复。
There's SIGTSTP, a signal for pausing processes, which you could use if you have two processes, but signals have several drawbacks so I wouldn't recommend using them. For a controlled, stable method you'd have to do it yourself using a mutex, where user pausing the playback leads to locking the mutex, and the thread doing the playback tries to lock the mutex . Like this:
If you need more communication between the two threads you could use the standard IPC mechanisms like pipes - you could then implement pausing and resuming based on that.