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 » MT and variables simple question
Re: MT and variables simple question [message #43229 is a reply to message #43224] Wed, 11 June 2014 08:16 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13980
Registered: November 2005
Ultimate Member
ManfredHerr wrote on Tue, 10 June 2014 15:59
My two cents:
Mutex locks are necessary only then when the "variable" is compound. For example the mentioned fifo. It must be guaranteed that the full fifo entry is written before a second thread can interrupt and read it. For simple variables like integers a.s.o. there is no need to protect because they are written and read in an "atomic" action. The writing thread cannot be interrupted during the write-operation.


Just to clarify, read/write is perhaps atomic, but a combination of them is not. Consider simple

int x;
...
x++;

this is broken in MT, because ++ are TWO atomic operations with respect to memory variable (read AND write), despite the fact that ISA is realizing that operation with single CPU opcode.

Also, you need to carefuly check your ISA to find out what fundamental types are really atomic. Plus be prepared for nasty effects like read/write reordering (use memory barriers).

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [SOLVED] Fix some memory leak in IpAddrInfo
Next Topic: [SOLVED][FeatureRequests]Use HttpRequest to upload large file
Goto Forum:
  


Current Time: Mon May 13 22:49:09 CEST 2024

Total time taken to generate the page: 0.02544 seconds