]> git.lizzy.rs Git - rust.git/commitdiff
Add support for std::thread::yield_now
authorDavid Cook <divergentdave@gmail.com>
Sun, 19 Apr 2020 00:31:02 +0000 (19:31 -0500)
committerDavid Cook <divergentdave@gmail.com>
Sun, 19 Apr 2020 00:31:02 +0000 (19:31 -0500)
src/shims/foreign_items/posix.rs
src/shims/foreign_items/windows.rs
tests/run-pass/sync.rs

index 3ececb9c20bbdb684696ce88a503dd4f9895afb8..35decd6ddbf2edaabb5a1ccdd9fa11d32620e482 100644 (file)
@@ -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.
index 1d17cbcefdeec7357cc2b378d741904940088204..0125127a9f4000ef8fa9184f544168339c0e7921 100644 (file)
@@ -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" => {
index 90885880e681f39a1b3870b6efc12df0aefb6d98..a4fd6f584c5890b26dccfa914acbb4636fc75ba4 100644 (file)
@@ -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();
+}