我想要暂停一个pthread吗? [英] How to pause a pthread ANY TIME I want?

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

问题描述

最近我开始将ucos-ii连接到Ubuntu PC。



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



如何在Linux中的c中睡觉或暂停PThread



我在下面的网站上找到了一个解决方案,但由于它已经过时,因此无法构建。它使用Linux中的过程在ucos-ii中模拟任务(像我们的Linux中的过程)。



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



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

解决方案

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



参见例如,回答E.4 这里


POSIX标准不提供线程A可以暂停执行另一个线程B的机制,而不需要从B进行协作。实现挂起/重新启动机制的唯一方法是使B定期检查挂起请求的一些全局变量,然后暂停自身处于条件变量,另一个线程可以后来发出信号重新启动B。


该常见问题解答解释了几种非标准方式这样做,一个在Solaris中,一个在LinuxThreads(现在已经过时了;不要将其与Linux上的当前线程混淆);这些都不适用于您的情况。


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

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

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

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.

解决方案

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.

See, for example, answer E.4 here:

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.

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天全站免登陆