与poco的tryJoin混淆

编程入门 行业动态 更新时间:2024-10-24 22:27:39
本文介绍了与poco的tryJoin混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好。我是poco线程类的新用法。 用例: 我正在使用poco tryJoin等待5秒钟..部分代码是

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

问题: 我看到有5秒延迟线程未能停止,如果在上面没有看到延迟,如果情况 并且语句已成功停止线程被打印没有任何延迟 为什么

tryJoin( 5000 )

没有延迟? 描述如果tryJoin说它是那个磨坊秒

bool tryJoin( long 毫秒); /// 最多等待线程的给定时间间隔 /// 完成。如果线程已完成,则返回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混淆

本文发布于:2023-07-27 11:52:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222306.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:poco   tryJoin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!