tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.14k stars 111 forks source link

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

Closed faern closed 2 years ago

faern commented 4 years ago

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 commented 3 years ago

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

faern commented 3 years ago

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.