Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AlexM

multi-thread access

This topic is 5812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''m accessing a common variable between two threads. Unfortunately, even though I protect the variable using a CCriticalSection, a problem occurs. When one thread updates the variable, the other thread doesn''t see the new value. I''m not sure exactly why - either when VC compiles the code it optimizes it by keeping a constant copy of the variable and not looking it up again, or the function pushes the variable to a register and it isn''t looked up again. either way, the new value is not seen. I''ve tried encompassing the lookup in a function, that doesn''t work either. How does one handle this?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
just like you said. i''ve never had a problem using critical sections yet, and i''ve used them in C, C++ classes, accessing global and/or class vars w/o a problem.

have you called InitializeCriticalSection at the start?

don''t know what else to suggest. they''re pretty easy to use.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
use volatile

Share this post


Link to post
Share on other sites
I''m using CCriticalSection (MFC)
and critical sections aren''t the problem, the problem is getting VC to see the true value, rather than a copy of the variable that it pushed up to a register (I think) because it isn''t changed in the current thread (but might be changed in another). I hope i''m right on this diagnosis. I checked memory addresses, they matched, but the values were different.

Share this post


Link to post
Share on other sites
lol, thanks. I knew there was something simple like that, just never had to deal with it before.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!