Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C++
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
C++
tryJoin(5000)
?

Description if tryJoin says that it was for that mill sec
C++
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.
Posted

1 solution

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[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900