与poco的tryJoin混淆 [英] confusion with tryJoin of poco

查看:124
本文介绍了与poco的tryJoin混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是poco线程类的新用法。



用例:

我正在使用poco tryJoin等待5秒钟..部分代码是



  if (Thread.tryJoin( 5000 )){
cout<< 已停止线程成功;
}
else
cout<< 未能停止;



问题:

我看到有5秒延迟线程未能停止,如果在上面没有看到延迟,如果情况

并且语句已成功停止线程被打印没有任何延迟



为什么

 tryJoin( 5000 

没有延迟?



描述如果tryJoin说它是那个磨坊秒

  bool  tryJoin( long 毫秒); 
/// 最多等待线程的给定时间间隔
< span class =code-summarycomment> /// 完成。如果线程已完成,则返回true,
/// 否则为false。

解决方案

最多等待线程的给定间隔



这意味着它不会等待超过指定的时间。即便如此,它只会在线程仍在运行时等待。

如果您希望在特定时间暂停代码,请使用 睡眠功能 [ ^ ]。


Hi. I am new to the usage of poco thread class.

Usecase :
I am using poco tryJoin to wait for some 5 sec..part of code is

if(Thread.tryJoin(5000)) {
   cout<<"stopped thread successfully";
 }
 else 
	cout<<"failed to stop";


Problem:
I see that there is 5 sec delay if the thread failed to stop, where as the delay is not seen in above if case
and the statement "stopped thread successfully" was printed without any delay

why no delay when

tryJoin(5000)

?

Description if tryJoin says that it was for that mill sec

bool tryJoin(long milliseconds);
		/// Waits for at most the given interval for the thread 
		/// to complete. Returns true if the thread has finished,
		/// false otherwise.

解决方案

Waits for at most the given interval for the thread 


That means that it will not wait longer than the time specified. And even then it will only wait if the thread is still running.
If you wish to pause your code for a specific time then use the Sleep function[^].


这篇关于与poco的tryJoin混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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