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

Should ParVec have poisoning behavior for panics? #3

Open
abonander opened this issue Apr 30, 2015 · 2 comments
Open

Should ParVec have poisoning behavior for panics? #3

abonander opened this issue Apr 30, 2015 · 2 comments

Comments

@abonander
Copy link
Contributor

A thread panicking while operating on a ParSlice could leave an incomplete result, similar to what would happen if a thread panicked while holding a MutexGuard or a RWLockWriteGuard. This suggests that ParSlice should have similar poisoning behavior.

However, poisoning a whole vector just because a thread panicked while holding a subslice seems like overkill. As a compromise, unwrapping a ParVec could return two vectors: one with all the elements from healthy (unpoisoned) subslices, and one with the contaminated elements from poisoned subslices. This would add complexity to the implementation as subslices are currently only tracked via the strong refcount on Arc, and would also require additional allocations where the current API uses existing storage.

But I would also argue that ParVec should not poison altogether, because it does not allow actual concurrent (or mutually exclusive) access to its elements; each is only ever touched by either the originating thread, or the thread that its containing ParSlice was sent to, and never at the same time, mutably or otherwise. In this way, incomplete results seem more like a logic error than undefined behavior, and thus should be handled by the user.

It is clear some discussion is merited here. Is ParVec safe as it is, or is it hiding dangerous, undefined behavior behind a "safe" API?

cc @gankro, @huonw

@reem
Copy link
Member

reem commented Feb 12, 2016

It seems reasonable to me to just poison the entire vector, and allow the user to recover from poisoning the same way Mutex and RwLock do.

@reem
Copy link
Member

reem commented Feb 12, 2016

It should be noted that poisoning is not actually necessary for safety reasons, it's just a nice-to-have as it makes the behavior under panics a bit more reasonable.

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

No branches or pull requests

2 participants