Multithread sync

Started by
5 comments, last by kuphryn 18 years, 1 month ago
If I have aglobal variable in a program, and lets say there are 2 cpus in the processor. Then there is no problem for two threads to both read that variable at the same time, right? I only need to worry to get garbage when one reads it while the other writes it. Is that true? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
What language is this?
correct - read access never hurt anyone :). it's only when one or more threads attempts to write that you get problems.
Quote:Original post by Dave
What language is this?

Isnt this a common problem to all languages?

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Quote:Original post by The C modest god
Quote:Original post by Dave
What language is this?

Isnt this a common problem to all languages?


It is - unless you have some built-in mecanism in the langage that lock variables when reading or writing them (but then your question doesn't make sense [smile]).

The main problem is not with reading, it is with writing. But eitherway, you'll have to write the variable at least once before reading it :)

Regards,
Any data that is shared between threads should be treated with extreme caution - particularly vectors, or other iterated containers. Such data should be protected by a mutex.

Even searches (ostensibly a read) on iterated containers should be mutexed - should another thread write to the container, potentially the container's internal implementation could be moved, or a bounds iterator could be invalidated.


Winterdyne Solutions Ltd is recruiting - this thread for details!
Correct. Another possible solution is critical sections.

Kuphryn

This topic is closed to new replies.

Advertisement