如何暂停pthread任何时间我想要? [英] How to pause a pthread ANY TIME I want?

查看:255
本文介绍了如何暂停pthread任何时间我想要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始将ucos-ii移植到Ubuntu PC。

recently I set out to port ucos-ii to Ubuntu PC.

我们知道,不可能模拟ucos-ii中的process只需在pthread的回调函数的while循环中添加一个标志,以执行暂停和恢复(如下面的解决方案)。因为ucos-ii中的进程可以随时暂停或恢复!

As we know, it's not possible to simulate the "process" in the ucos-ii by simply adding a flag in "while" loop in the pthread's call-back function to perform pause and resume(like the solution below). Because the "process" in ucos-ii can be paused or resumed at any time!

How to sleep or pause a PThread in c on Linux

我在下面的网站上找到了一个解决方案,但它不能构建,因为它已过期。它使用Linux中的进程来模拟ucos-ii中的任务(像我们Linux中的进程一样)。

I have found one solution on the web-site below, but it can't be built because it's out of date. It uses the process in Linux to simulate the task(acts like the process in our Linux) in ucos-ii.

http://www2.hs-esslingen.de/~zimmerma/software/index_uk.html

如果pthread可以像任何时候可以暂停和恢复的过程一样,请告诉我一些相关的功能,我可以自己弄清楚。如果不能,我想我应该关注老的解决方案。非常感谢。

If pthread can act like the process which can be paused and resumed at any time, please tell me some related functions, I can figure it out myself. If it can't, I think I should focus on the older solution. Thanks a lot.

推荐答案

如果在条件变量不足的特定点停止,则不能使用pthread 。 pthread接口不包括挂起/恢复功能。

If stopping at specific points with a condition variable is insufficient, then you can't do this with pthreads. The pthread interface does not include suspend/resume functionality.

例如,请参见answer E.4 此处

See, for example, answer E.4 here:


POSIX标准不提供机制,通过该机制,线程A可以暂停另一个线程B的执行,而不需要B的协作。实现暂停/重新启动机制的唯一方式是周期性地为暂停请求检查一些全局变量,然后根据条件

The POSIX standard provides no mechanism by which a thread A can suspend the execution of another thread B, without cooperation from B. The only way to implement a suspend/restart mechanism is to have B check periodically some global variable for a suspend request and then suspend itself on a condition variable, which another thread can signal later to restart B.

这个FAQ回答继续描述一些非标准的方法做它,一个在Solaris和一个在LinuxThreads(这已经过时;不要混淆它与当前线程在Linux上);这些都不适用于您的情况。

That FAQ answer goes on to describe a couple of non-standard ways of doing it, one in Solaris and one in LinuxThreads (which is now obsolete; do not confuse it with current threading on Linux); neither of those apply to your situation.

这篇关于如何暂停pthread任何时间我想要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆