Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Stop a thread
Re: Stop a thread [message #20266 is a reply to message #20260] Fri, 06 March 2009 08:34 Go to previous messageGo to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
darthspawn wrote on Thu, 05 March 2009 17:12

"volatile atomic"

volatile = C/C++ keyword, it tells compiler the value can change from "outside" in memory while the current code is running. With general variables like in:
bool run = true;
while ( run ) {
  run = false;   //change "inside" code
}

The compiler can optimize the whole code to read the content of variable from memory into register once, and then work only with register and ignore the memory.
So if the value would change only in the memory outside of the current code, the final code will not catch it and would run in infinite loop.
With "volatile" the compiler knows the value has to be re-read from memory all the time to keep it fresh and allow modifications from "outside" to be catch ASAP.

Atomic is defined as "long" in Mt.h, and that's because reading/writing of long at x86 is atomic operation, i.e. you either did read/write whole long, or you didn't at all, you can't get interrupted in between. Actually there's special machine code instruction to compare+exchange 8/16/32b value atomically (CMPXCHG and CMPXCHG8B), which allows you to write some new value into memory only if the old value didn't change yet (very handy in MT where more then one thread access and change the same memory variable and need to cooperate in some way, like doing auto-increment of IDs for example).
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to catch http client timeout error
Next Topic: how to exit from Socket.Read()
Goto Forum:
  


Current Time: Mon May 13 09:16:54 CEST 2024

Total time taken to generate the page: 0.02204 seconds