Re: Why can't I start a thread twice?



Hi Peter

Peter Duniho wrote:
On Sat, 02 May 2009 12:34:53 -0700, Chuan C. <spam@xxxxxxx> wrote:
[...]
Furthermore, the code you posted doesn't even bother to make "go"
volatile,

Could you explaint that?

Since the variable isn't marked as "volatile", the compiler and run-time
are both free to make optimizations to access to the variable, including
caching its value locally. Without "volatile" or some other
synchronization mechanism, there's no guarantee that just because one
thread set the variable to a particular value, that another thread will
ever see that particular value.

Sometimes it will work. In fact, often times it will work. But without
a guarantee, the code is buggy regardless.

Thanks again.

The literature I was following did not mention that. I've sent a "bug
report" to the author.

CU
Chuan.
.



Relevant Pages

  • Re: shared memory between processes
    ... POSIX, for example, states several conditions under which memory visiblity ... and not one of them uses or requires 'volatile'. ... mechanisms already guarantee thread safety.) ... compiler no knowledge of the functions, thus the compiler must assume they ...
    (comp.os.linux.development.system)
  • Re: Interlocked operations, volatile
    ... to guarantee that read/write operations are completed in proper order? ... Is it true that the goal of 'volatile' is the same? ... Is it nessesary to use 'int* volatile ptr' or some interlocked ...
    (comp.programming.threads)
  • Re: Volatile happens before question
    ... I believe the exact language talks about synchronization ... With volatile, this strengthens the requirements slightly by also requiring ... I don't think that you get the opposite guarantee. ... I think the key is that you get "happens-before" guarantees but not ...
    (comp.lang.java.programmer)
  • Re: [PATCH tip/core/rcu 08/10] rcu: Add a TINY_PREEMPT_RCU
    ... I'd be concerned by the fact that there is no strong ordering guarantee ... My concern is that the compiler might be allowed to turn your code into: ... previous accesses to volatile objects have stabilized and no subsequent ...
    (Linux-Kernel)
  • Re: When is "volatile" used instead of "lock" ?
    ... synchronization but for acquire/release semantics. ... Again you're treating atomicity as almost interchangeable with ... marked as volatile, but it also has no thread-affinity. ... guarantee, you'd be entirely at the mercy of type authors for *all* ...
    (microsoft.public.dotnet.languages.csharp)