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 » Simple class to handle variables used by different threads
Re: Simple class to handle variables used by different threads [message #45047 is a reply to message #45046] Mon, 24 August 2015 19:08 Go to previous messageGo to previous message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Of course, making variable 'volatile' actually doesn't guarantee anything when we discuss multithreading issues. It just says to compiler 'please, don't optimize it as it may be changed outside your source code'.

The reason it 'sort of' works under modern x86/x64 systems is that modern CPUs change char/int variable with single CPU instruction which effectively avoids multithreading issues. If your variable is anything but char/int (+int64 under x64) you may have multithreading issues when variable is accessed while being updated in another thread.

You should also notice that under arm/mips systems you may have issues even with int32/int64 depending on particular CPU used.

I guess we have nice solution in U++. There's Atomic type which guarantees no multithreading issues with possible support with native OS/CPU commands. So why should we really duplicate its functionality?
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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: How to just Post data ?
Next Topic: Mt.cpp broken compile using 9604 nightly snap-shot
Goto Forum:
  


Current Time: Wed May 08 23:21:08 CEST 2024

Total time taken to generate the page: 0.02113 seconds