From 8878b128baddfa4ee38e4f9c43be75abe0edcd3d Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 21 Jul 2011 12:11:05 -0700 Subject: More work on word-count. Updated the MapReduce protocol so that it's correct more often. It's still not perfect, but the bugs repro less often now. Also found a race condition in channel sending. The problem is that send and receive both need to refer to the _unread field in circular_buffer. For now I just grabbed the port lock to send. We can probably get around this by using atomics instead. --- src/rt/rust_chan.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/rt/rust_chan.cpp') diff --git a/src/rt/rust_chan.cpp b/src/rt/rust_chan.cpp index 92edaa77650..d04f5ee8ff5 100644 --- a/src/rt/rust_chan.cpp +++ b/src/rt/rust_chan.cpp @@ -71,9 +71,16 @@ void rust_chan::disassociate() { * Attempt to send data to the associated port. */ void rust_chan::send(void *sptr) { + rust_scheduler *sched = kernel->sched; + I(sched, !port->is_proxy()); + + rust_port *target_port = port->referent(); + // TODO: We can probably avoid this lock by using atomic operations in + // circular_buffer. + scoped_lock with(target_port->lock); + buffer.enqueue(sptr); - rust_scheduler *sched = kernel->sched; if (!is_associated()) { W(sched, is_associated(), "rust_chan::transmit with no associated port."); @@ -88,8 +95,6 @@ void rust_chan::send(void *sptr) { task->get_handle(), port->as_proxy()->handle()); buffer.dequeue(NULL); } else { - rust_port *target_port = port->referent(); - scoped_lock with(target_port->lock); if (target_port->task->blocked_on(target_port)) { DLOG(sched, comm, "dequeued in rendezvous_ptr"); buffer.dequeue(target_port->task->rendezvous_ptr); -- cgit 1.4.1-3-g733a5