Home » U++ Library support » U++ MT-multithreading and servers » Wait for other Threads
Re: Wait for other Threads [message #46582 is a reply to message #46568] |
Fri, 03 June 2016 09:59  |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
I didn't study the original problem, this comment is more a reply to koldo's response.
Operations with int often are naturally atomic even without guards (either completely atomic like ++int, or with possible errors in result value, but undamaged content of int, like int++).
That said, you still can't just increase it in one thread, and display it in second, unless you tell the compiler, that the content can be changed outside of current thread. So you should either use "volatile int" (if you know, what you are doing, and how CPU works), or std::atomic<int> ..
like here is some (a bit too short?) tutorial:
http://baptiste-wicht.com/posts/2012/07/c11-concurrency-tuto rial-part-4-atomic-type.html
|
|
|
Goto Forum:
Current Time: Fri Jun 27 17:30:52 CEST 2025
Total time taken to generate the page: 0.03507 seconds
|