aboutsummaryrefslogtreecommitdiff
path: root/src/rt/sync
diff options
context:
space:
mode:
authorMichael Bebenita <[email protected]>2010-09-07 23:37:51 -0700
committerMichael Bebenita <[email protected]>2010-09-07 23:37:51 -0700
commit7f6d8b95bd3340ea5fa32874243dac036208105b (patch)
tree7010caf355578adc06a0919df97b0418683ba41f /src/rt/sync
parentLots of design changes around proxies and message passing. Made it so that do... (diff)
downloadrust-7f6d8b95bd3340ea5fa32874243dac036208105b.tar.xz
rust-7f6d8b95bd3340ea5fa32874243dac036208105b.zip
Fixed race in the rust kernel.
Diffstat (limited to 'src/rt/sync')
-rw-r--r--src/rt/sync/sync.cpp9
-rw-r--r--src/rt/sync/sync.h3
2 files changed, 10 insertions, 2 deletions
diff --git a/src/rt/sync/sync.cpp b/src/rt/sync/sync.cpp
index 70e5077c..fdfc0652 100644
--- a/src/rt/sync/sync.cpp
+++ b/src/rt/sync/sync.cpp
@@ -11,6 +11,10 @@ void sync::yield() {
#endif
}
+rust_thread::rust_thread() : _is_running(false) {
+ // Nop.
+}
+
#if defined(__WIN32__)
static DWORD WINAPI
#elif defined(__GNUC__)
@@ -36,6 +40,7 @@ rust_thread::start() {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&thread, &attr, rust_thread_start, (void *) this);
#endif
+ _is_running = true;
}
void
@@ -46,10 +51,10 @@ rust_thread::join() {
pthread_join(thread, NULL);
#endif
thread = 0;
+ _is_running = false;
}
bool
rust_thread::is_running() {
- // TODO: This may be broken because of possible races.
- return thread;
+ return _is_running;
}
diff --git a/src/rt/sync/sync.h b/src/rt/sync/sync.h
index 562d2a1b..3829dafe 100644
--- a/src/rt/sync/sync.h
+++ b/src/rt/sync/sync.h
@@ -15,12 +15,15 @@ public:
* Thread utility class. Derive and implement your own run() method.
*/
class rust_thread {
+private:
+ volatile bool _is_running;
public:
#if defined(__WIN32__)
HANDLE thread;
#else
pthread_t thread;
#endif
+ rust_thread();
void start();
virtual void run() {