Skip to content

Commit 7b69a62

Browse files
committed
Add support for std::thread::yield_now
1 parent 11cd87e commit 7b69a62

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/shims/foreign_items/posix.rs

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
312312
// We do not support forking, so there is nothing to do here.
313313
this.write_null(dest)?;
314314
}
315+
"sched_yield" => {
316+
this.write_null(dest)?;
317+
}
315318

316319
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
317320
// These shims are enabled only when the caller is in the standard library.

src/shims/foreign_items/windows.rs

+5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
201201
// FIXME: we should set last_error, but to what?
202202
this.write_null(dest)?;
203203
}
204+
"SwitchToThread" => {
205+
// Note that once Miri supports concurrency, this will need to return a nonzero
206+
// value if this call does result in switching to another thread.
207+
this.write_null(dest)?;
208+
}
204209

205210
// Better error for attempts to create a thread
206211
"CreateThread" => {

tests/run-pass/sync.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010
test_rwlock_stdlib();
1111
}
1212
test_spin_loop_hint();
13+
test_thread_yield_now();
1314
}
1415

1516
fn test_mutex_stdlib() {
@@ -56,3 +57,7 @@ impl<T> TryLockErrorExt<T> for TryLockError<T> {
5657
fn test_spin_loop_hint() {
5758
atomic::spin_loop_hint();
5859
}
60+
61+
fn test_thread_yield_now() {
62+
std::thread::yield_now();
63+
}

0 commit comments

Comments
 (0)