C
Cool Guy
using System;
using System.Threading;
class EntryPoint
{
static void Main() {
Test t = new Test();
t.DoSomething();
}
}
class Test
{
object o;
public void DoSomething() {
o = new Object(); // write to o
new Thread(new ThreadStart(ThreadJob)).Start();
}
void ThreadJob() {
DoSomethingWith(o); // read from o
}
}
------
The only write to /o/ happens before the new thread is created. In the new
thread a read from /o/ happens.
I've been told that a new thread's view of memory is synchronized with that
of the thread that created it. So if this is true I assume this code is
safe (or could the write to /o/ be re-ordered to *after* the new thread's
creation?).
using System.Threading;
class EntryPoint
{
static void Main() {
Test t = new Test();
t.DoSomething();
}
}
class Test
{
object o;
public void DoSomething() {
o = new Object(); // write to o
new Thread(new ThreadStart(ThreadJob)).Start();
}
void ThreadJob() {
DoSomethingWith(o); // read from o
}
}
------
The only write to /o/ happens before the new thread is created. In the new
thread a read from /o/ happens.
I've been told that a new thread's view of memory is synchronized with that
of the thread that created it. So if this is true I assume this code is
safe (or could the write to /o/ be re-ordered to *after* the new thread's
creation?).