From 7b69a6271e3e1469da26dce61284dbcb1face302 Mon Sep 17 00:00:00 2001 From: David Cook Date: Sat, 18 Apr 2020 19:31:02 -0500 Subject: [PATCH] Add support for std::thread::yield_now --- src/shims/foreign_items/posix.rs | 3 +++ src/shims/foreign_items/windows.rs | 5 +++++ tests/run-pass/sync.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/src/shims/foreign_items/posix.rs b/src/shims/foreign_items/posix.rs index 3ececb9c20bb..35decd6ddbf2 100644 --- a/src/shims/foreign_items/posix.rs +++ b/src/shims/foreign_items/posix.rs @@ -312,6 +312,9 @@ fn emulate_foreign_item_by_name( // We do not support forking, so there is nothing to do here. this.write_null(dest)?; } + "sched_yield" => { + this.write_null(dest)?; + } // Incomplete shims that we "stub out" just to get pre-main initialization code to work. // These shims are enabled only when the caller is in the standard library. diff --git a/src/shims/foreign_items/windows.rs b/src/shims/foreign_items/windows.rs index 1d17cbcefdee..0125127a9f40 100644 --- a/src/shims/foreign_items/windows.rs +++ b/src/shims/foreign_items/windows.rs @@ -201,6 +201,11 @@ fn emulate_foreign_item_by_name( // FIXME: we should set last_error, but to what? this.write_null(dest)?; } + "SwitchToThread" => { + // Note that once Miri supports concurrency, this will need to return a nonzero + // value if this call does result in switching to another thread. + this.write_null(dest)?; + } // Better error for attempts to create a thread "CreateThread" => { diff --git a/tests/run-pass/sync.rs b/tests/run-pass/sync.rs index 90885880e681..a4fd6f584c58 100644 --- a/tests/run-pass/sync.rs +++ b/tests/run-pass/sync.rs @@ -10,6 +10,7 @@ fn main() { test_rwlock_stdlib(); } test_spin_loop_hint(); + test_thread_yield_now(); } fn test_mutex_stdlib() { @@ -56,3 +57,7 @@ fn would_block(&self) -> bool { fn test_spin_loop_hint() { atomic::spin_loop_hint(); } + +fn test_thread_yield_now() { + std::thread::yield_now(); +}