tokio-rs / loom

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

Add support for mpsc channels #118

Closed vakaras closed 4 years ago

vakaras commented 4 years ago

Adds Loom mocks for std::sync::mpsc. Also, adds unimplemented stubs for std::sync::barrier that the code that depends on them could be at least compiled.

Note: This PR includes the changes from #88, so you probably want to merge it first. cc: @pop

carllerche commented 4 years ago

I merged #88, would you be able to rebase on that? Thanks.

vakaras commented 4 years ago

I merged #88, would you be able to rebase on that? Thanks.

Thank you for merging #88! I have rebased this PR.

vakaras commented 4 years ago

Looks good, I skimmed and it matches my expectation. I did have one question, which I added inline.

For some reason, I do not see your question. (I also have not received any notification about it.)

carllerche commented 4 years ago

@vakaras very strange...

You have one Synchronize for the entire channel. I believe synchronization should happen on a message basis, no? So, you would have one Synchronize value per message. When you recv a message, you apply the synchronization received for that message.

vakaras commented 4 years ago

Good point. Since mpsc supports multiple producers, we need to synchronize on a message basis. Thanks for pointing this out! I will update the PR.

vakaras commented 4 years ago

Since the documentation claims that mpsc channels preserve the order of the messages, I changed the code to have one synchronization point for senders and a synchronization point per message for receivers. As a result, if thread t1 managed to send m1 before t2 sent m2, the thread that received m2will know that m1 was already sent and received. However, the receiver of m1 will know nothing about m2.