Skip to content

Commit

Permalink
runtime: fix a race condition with async RPCs.
Browse files Browse the repository at this point in the history
session.rs has code like:

    while !rpc_queue::empty() {
        try!(process_kern_queued_rpc(stream, &mut session))
    }

    // A

    if mailbox::receive() != 0 {
        try!(process_kern_message(waiter, Some(stream), &mut session));
    }

If both an async and a mailbox RPC (async or large sync) are posted
at point A then they will be processed out of order.
This commit fixes the issue by flushing the async RPC queue before
posting any RPC to the mailbox.
whitequark committed Nov 1, 2016
1 parent 6fcd57a commit b30734a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions artiq/runtime.rs/libksupport/lib.rs
Original file line number Diff line number Diff line change
@@ -107,6 +107,7 @@ extern fn send_rpc(service: u32, tag: *const u8, data: *const *const ()) {
extern { fn strlen(s: *const c_char) -> size_t; }
let tag = unsafe { slice::from_raw_parts(tag, strlen(tag as *const c_char)) };

while !rpc_queue::empty() {}
send(&RpcSend {
async: false,
service: service,
@@ -130,6 +131,7 @@ extern fn send_async_rpc(service: u32, tag: *const u8, data: *const *const ()) {
}).unwrap_or_else(|err| {
assert!(err.kind() == std::io::ErrorKind::WriteZero);

while !rpc_queue::empty() {}
send(&RpcSend {
async: true,
service: service,

0 comments on commit b30734a

Please sign in to comment.