Home » U++ Library support » U++ MT-multithreading and servers » How to close a Thread?
Re: How to close a Thread? [message #38024 is a reply to message #38022] |
Wed, 28 November 2012 17:05   |
|
Hi NilaT
The problem is that IsOpen() does something slightly different than you think Thread docs | bool IsOpen() const
Thread represents an existing thread. Note that the thread can be already finished and not running anymore (calling to Wait in that case returns immediately).
| I.e. it returns false only before the thread is started and true always after it started, regardless of the current state. Other threads have no idea about what happens elsewhere.
The only reliable way to end a thread is to finish it from within. If you want to stop all running threads, just call ShutdownThreads() and make sure that all threads (well, except the main one, ussually) check periodically state of IsShutdownThreads(). If you need to stop only one particular thread, you must create your own flag that you can set in main thread to signalize the other one to finish itself. If necessary, the thread can also report that it is closing in similar way.
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Fri Jul 18 09:57:25 CEST 2025
Total time taken to generate the page: 0.03966 seconds
|