|
-
January 7th, 2010, 03:26 PM
#14
Re: Assigning value to a volatile string
What I wanted to say is this:
1. multi-threaded access to a shared resource _must_ be protected by a mutex (even if it is only a read, as some-thread else might be writing to it.
2. the use of the keyword volatile _alone_ does not make anything thread-safe
3. But the combined use of the keyword volatile and the use of the lockingPtr concept adds a compile-time check for the use of concurrent resources and it's definitely worth having a look at.
I have read most of the discussions in the thread (and links) that Codeplug referred to this afternoon, but in my opinion, they all concentrate on the question "does the keyword 'volatile' make the access to a variable thread-safe?". NO, it doesn't. Only the combination of 2. and 3. above adds some (compiler) help to the programmer to get it right. There might be hacks to circumvent this, and if compiler optimization matters, it might be counter-productive, but I personally find it useful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|