Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Use futex implementation for Once #125942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timokroeger
Copy link

Keep the queue implementation for win7.
Inspired by PR #121956

@rustbot
Copy link
Collaborator

rustbot commented Jun 3, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Amanieu (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 3, 2024
@timokroeger
Copy link
Author

@rustbot label O-windows

@rustbot rustbot added the O-windows Operating system: Windows label Jun 3, 2024
@timokroeger
Copy link
Author

timokroeger commented Jun 3, 2024

r? @ChrisDenton

@rustbot rustbot assigned ChrisDenton and unassigned Amanieu Jun 3, 2024
@workingjubilee
Copy link
Contributor

cc @joboet who has touched related API including #99505

Copy link
Contributor

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me, just one small nit.

library/std/src/sys/sync/once/mod.rs Outdated Show resolved Hide resolved
Keep the queue implementation for win7.
Inspired by PR rust-lang#121956
@ChrisDenton
Copy link
Contributor

Thanks again!

@bors r+

@bors
Copy link
Contributor

bors commented Jun 4, 2024

📌 Commit fa58d1b has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 4, 2024
@ChrisDenton
Copy link
Contributor

@bors rollup=iffy

While I don't anticipate issues, changing the Once implementation could potentially cause problems so it shouldn't be rolled up with other PRs absolutely unless necessary.

@workingjubilee
Copy link
Contributor

has been waiting for 3 days, it seems.
@bors p=3

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2024
…risDenton

Windows: Use futex implementation for `Once`

Keep the queue implementation for win7.
Inspired by PR rust-lang#121956

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
@bors
Copy link
Contributor

bors commented Jun 7, 2024

⌛ Testing commit fa58d1b with merge d79ed88...

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-aux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Jun 8, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 8, 2024
@ChrisDenton
Copy link
Contributor

The failure was in miri's tests, which look like they've found a genuine deadlock. Only it occurred in the thread parker (via mpmc), not in Once code:

error: deadlock: the evaluated program deadlocked
##[error]   --> /checkout/library/std/src/sys/sync/thread_parking/windows.rs:120:90
    |
120 |             c::WaitOnAddress(self.ptr(), &PARKED as *const _ as c::LPVOID, 1, c::INFINITE);
    |                                                                                          ^ the evaluated program deadlocked
    |
    = note: BACKTRACE:
    = note: inside `realstd::sys::sync::thread_parking::windows::Parker::park` at /checkout/library/std/src/sys/sync/thread_parking/windows.rs:120:90: 120:91
    = note: inside `realstd::thread::Thread::park` at /checkout/library/std/src/thread/mod.rs:1361:18: 1361:53
    = note: inside `realstd::thread::park` at /checkout/library/std/src/thread/mod.rs:1104:9: 1104:25
    = note: inside `realstd::sync::mpmc::context::Context::wait_until` at /checkout/library/std/src/sync/mpmc/context.rs:139:17: 139:31
    = note: inside closure at /checkout/library/std/src/sync/mpmc/list.rs:444:27: 444:50
    = note: inside closure at /checkout/library/std/src/sync/mpmc/context.rs:50:13: 50:18
    = note: inside closure at /checkout/library/std/src/sync/mpmc/context.rs:58:31: 58:37
    = note: inside `realstd::thread::LocalKey::<core::cell::Cell<core::option::Option<realstd::sync::mpmc::context::Context>>>::try_with::<{closure@realstd::sync::mpmc::context::Context::with<{closure@realstd::sync::mpmc::list::Channel<test::event::CompletedTest>::recv::{closure#1}}, ()>::{closure#1}}, ()>` at /checkout/library/std/src/thread/local.rs:283:12: 283:27
    = note: inside `realstd::sync::mpmc::context::Context::with::<{closure@realstd::sync::mpmc::list::Channel<test::event::CompletedTest>::recv::{closure#1}}, ()>` at /checkout/library/std/src/sync/mpmc/context.rs:53:9: 62:15
    = note: inside `realstd::sync::mpmc::list::Channel::<test::event::CompletedTest>::recv` at /checkout/library/std/src/sync/mpmc/list.rs:434:13: 455:15
    = note: inside `realstd::sync::mpmc::Receiver::<test::event::CompletedTest>::recv` at /checkout/library/std/src/sync/mpmc/mod.rs:307:43: 307:58
    = note: inside `realstd::sync::mpsc::Receiver::<test::event::CompletedTest>::recv` at /checkout/library/std/src/sync/mpsc/mod.rs:849:9: 849:26
    = note: inside `test::run_tests::<{closure@test::run_tests_console::{closure#2}}>` at /checkout/library/test/src/lib.rs:434:27: 434:36
    = note: inside `test::run_tests_console` at /checkout/library/test/src/console.rs:322:5: 322:70
    = note: inside `test::test_main` at /checkout/library/test/src/lib.rs:142:19: 142:59
    = note: inside `test::test_main_static` at /checkout/library/test/src/lib.rs:164:5: 164:40
    = note: inside `main`

This will need some investigation.

@timokroeger
Copy link
Author

timokroeger commented Jun 9, 2024

Reproducible on x86_64 windows 11 with: ./x miri --stage 1 library/std -- sync::once::tests::wait_for_force_to_finish
When skipping the wait_for_force_to_finish test case everything else passes.

test sync::once::tests::wait_for_force_to_finish has been running for a long time
error: deadlock: the evaluated program deadlocked
   --> rust\library\std\src\sys\sync\thread_parking\windows.rs:120:90
    |
120 |             c::WaitOnAddress(self.ptr(), &PARKED as *const _ as c::LPVOID, 1, c::INFINITE);
    |                                                                                          ^ the evaluated program deadlocked
    |
    = note: BACKTRACE:
    = note: inside `realstd::sys::sync::thread_parking::windows::Parker::park` at rust\library\std\src\sys\sync\thread_parking\windows.rs:120:90: 120:91    
    = note: inside `realstd::thread::Thread::park` at rust\library\std\src\thread\mod.rs:1360:18: 1360:53
    = note: inside `realstd::thread::park` at rust\library\std\src\thread\mod.rs:1103:9: 1103:25
    = note: inside `realstd::sync::mpmc::context::Context::wait_until` at rust\library\std\src\sync\mpmc\context.rs:139:17: 139:31
    = note: inside closure at rust\library\std\src\sync\mpmc\list.rs:444:27: 444:50
    = note: inside closure at rust\library\std\src\sync\mpmc\context.rs:50:13: 50:18
    = note: inside closure at rust\library\std\src\sync\mpmc\context.rs:58:31: 58:37
    = note: inside `realstd::thread::LocalKey::<core::cell::Cell<core::option::Option<realstd::sync::mpmc::context::Context>>>::try_with::<{closure@realstd::sync::mpmc::context::Context::with<{closure@realstd::sync::mpmc::list::Channel<test::event::CompletedTest>::recv::{closure#1}}, ()>::{closure#1}}, ()>` at rust\library\std\src\thread\local.rs:286:12: 286:27
    = note: inside `realstd::sync::mpmc::context::Context::with::<{closure@realstd::sync::mpmc::list::Channel<test::event::CompletedTest>::recv::{closure#1}}, ()>` at rust\library\std\src\sync\mpmc\context.rs:53:9: 62:15
    = note: inside `realstd::sync::mpmc::list::Channel::<test::event::CompletedTest>::recv` at rust\library\std\src\sync\mpmc\list.rs:434:13: 455:15        
    = note: inside `realstd::sync::mpmc::Receiver::<test::event::CompletedTest>::recv` at rust\library\std\src\sync\mpmc\mod.rs:307:43: 307:58
    = note: inside `realstd::sync::mpsc::Receiver::<test::event::CompletedTest>::recv` at rust\library\std\src\sync\mpsc\mod.rs:849:9: 849:26
    = note: inside `test::run_tests::<{closure@test::run_tests_console::{closure#2}}>` at rust\library\test\src\lib.rs:434:27: 434:36
    = note: inside `test::run_tests_console` at rust\library\test\src\console.rs:322:5: 322:70
    = note: inside `test::test_main` at rust\library\test\src\lib.rs:142:19: 142:59
    = note: inside `test::test_main_static` at rust\library\test\src\lib.rs:164:5: 164:40
    = note: inside `main`

error: deadlock: the evaluated program deadlocked
    --> library\std\src\sys\pal\windows\thread.rs:76:90
     |
76   |         let rc = unsafe { c::WaitForSingleObject(self.handle.as_raw_handle(), c::INFINITE) };
     |                                                                                          ^ the evaluated program deadlocked
     |
     = note: BACKTRACE on thread `sync::once::tests::wait_for_force_to_finish`:
     = note: inside `sys::pal::windows::thread::Thread::join` at library\std\src\sys\pal\windows\thread.rs:76:90: 76:91
...
note: inside `sync::once::tests::wait_for_force_to_finish`
    --> library\std\src\sync\once\tests.rs:115:13
     |
115  |     assert!(t2.join().is_ok());
     |             ^^^^^^^^^
...

error: deadlock: the evaluated program deadlocked
  |
  = note: the evaluated program deadlocked
  = note: (no span available)
  = note: BACKTRACE on thread `unnamed-2`:

error: deadlock: the evaluated program deadlocked
   --> library\std\src\sys\pal\windows\futex.rs:55:59
    |
55  |         c::WaitOnAddress(addr, compare_addr, size, timeout) == c::TRUE
    |                                                           ^ the evaluated program deadlocked
    |
    = note: BACKTRACE on thread `unnamed-3`:
    = note: inside `sys::pal::windows::futex::wait_on_address::<u32>` at library\std\src\sys\pal\windows\futex.rs:55:59: 55:60
note: inside `sys::pal::windows::futex::futex_wait::<u32>`
   --> library\std\src\sys\pal\windows\futex.rs:75:5
    |
75  |     wait_on_address(futex, expected, timeout) || api::get_last_error().code != c::ERROR_TIMEOUT
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
   --> library\std\src\sync\once\tests.rs:106:9
    |
106 | /         O.call_once(|| {
107 | |             called = true;
108 | |         });
    | |__________^

@fmease
Copy link
Member

fmease commented Jun 19, 2024

sync @bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants