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 #45049 is a reply to message #45046] Mon, 24 August 2015 19:13 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, depends on type and CPU...

Usually, if type is directly supported by CPU, it works.

Example of type that does not work is e.g. int64 in 32-bit mode. It is because it is, on CPU level, compound type...

Anyway, MT is not hard because of transfering data between threads. If you think about it, they have to get transfered at some point... The real issues are order:

if one thread does

a = a1;
b = b1;

then another thread can see b updated first. This is what barriers are for.

(Then, of course, there is an issue that you cannot never tell WHEN the change is visible in another thread, but that is really not a problem...)

And then, of course, serialization, which is about transactions:

a = a + 1;

now this, on CPU level is something like

read a into register
increment register // remember this point A
write register into a

Now imagine if another thread starts incrementing a at point A...

Well, there really is complex theory about lock-less multithreading, it is pretty tough stuff. I would not dare suggesting new MT tools before reading it all Smile

Mirek
 
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: Mon Apr 29 00:58:42 CEST 2024

Total time taken to generate the page: 0.04550 seconds