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

Expose a loom version of std::thread::park #133

Closed
faern opened this issue Apr 25, 2020 · 2 comments · Fixed by #240
Closed

Expose a loom version of std::thread::park #133

faern opened this issue Apr 25, 2020 · 2 comments · Fixed by #240

Comments

@faern
Copy link
Contributor

faern commented Apr 25, 2020

I have a library that uses std::thread::park() and Thread::unpark() for parking one thread when it must wait for another thread to reach a certain point. These tests deadlock under loom. I assume simply because the execution order it's currently evaluating demand that the thread waiting in park() make progress, and not the other ones. And this will obviously never happen.

I have currently gotten the tests to pass by conditionally replacing std::thread::park() with loom::thread::yield_now(). However, I'm not fully sure this tests what I want it to test 🤔

Since I don't know anything about loom internals etc I will put it like this: Would it make sense to expose loom::thread::park and potentially a corresponding loom::thread::Thread?

@Kixunil
Copy link

Kixunil commented Feb 3, 2021

I believe yield_now should be correct but clarification would be helpful.

@faern
Copy link
Contributor Author

faern commented Feb 4, 2021

If so, maybe an alias can be created? It's much easier to conditionally import loom::thread vs std::thread vs having to having more fine grained conditional import over specific functions.

hawkw added a commit that referenced this issue Nov 18, 2021
Currently, `loom`'s mock version of `std::thread` does not provide
mocked `std::thread::park` or `std::thread::Thread::unpark` APIs. It
would be nice to be able to use `loom` to test implementations of
synchronization primitives, and other code which uses `thread::park` and
`Thread::unpark`.

Fortunately, the `loom::rt` internals already contain the necessary
primitives to provide simulated versions of these APIs --- they're used
internally in the implementation of the mocked `Condvar` and `Notify`
types. This branch adds APIs for simulating `thread::park` and
`Thread::unpark`.

Closes #133
hawkw added a commit that referenced this issue Nov 22, 2021
Currently, `loom`'s mock version of `std::thread` does not provide
mocked `std::thread::park` or `std::thread::Thread::unpark` APIs. It
would be nice to be able to use `loom` to test implementations of
synchronization primitives, and other code which uses `thread::park` and
`Thread::unpark`.

Fortunately, the `loom::rt` internals already contain the necessary
primitives to provide simulated versions of these APIs --- they're used
internally in the implementation of the mocked `Condvar` and `Notify`
types. This branch adds APIs for simulating `thread::park` and
`Thread::unpark`.

Closes #133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants