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 #43224 is a reply to message #43223] Tue, 10 June 2014 15:59 Go to previous messageGo to previous message
ManfredHerr is currently offline  ManfredHerr
Messages: 67
Registered: February 2013
Location: Germany
Member
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.

In the case where only one thread writes the fifo and only one thread reads it this atomicy can be used by tricky programmers to get rid of the lock at all. They write the fifo entry completely before they increment the write index. So the reading thread will only become aware of the new entry when it is fully written. The same is with the reading thread. First the entry is read completely before the read index is incremented to allow for reuse.
 
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 23:43:36 CEST 2024

Total time taken to generate the page: 0.02330 seconds