Stream: general

Topic: Unpoisoning mutex


marmeladema (Apr 19 2020 at 15:43, on Zulip):

Is this possible to force unpoisoning a poisoned mutex?

Jonas Schievink (Apr 19 2020 at 15:45, on Zulip):

you can call .into_inner() on the PoisonError

marmeladema (Apr 19 2020 at 15:46, on Zulip):

yep, i tried that, but then i get back a mutexguard right? if i want to unlock that guard, i tried to drop(guard); but next mutex.lock still returned a poisoned guard

marmeladema (Apr 19 2020 at 15:49, on Zulip):

well i could use that guard to access again the underlying object, but since its poisoned its a very fragile thing to do i guess

simulacrum (Apr 19 2020 at 15:55, on Zulip):

no, poisoned mutexes aren't curable :)

marmeladema (Apr 19 2020 at 15:56, on Zulip):

Thats what i thought

RalfJ (Apr 19 2020 at 16:29, on Zulip):

simulacrum said:

no, poisoned mutexes aren't curable :)

that's susprisng, seems to me like the next regular unlock should cure them

simulacrum (Apr 19 2020 at 16:30, on Zulip):

That would be interesting

simulacrum (Apr 19 2020 at 16:32, on Zulip):

But it's not what is implemented today at least

simulacrum (Apr 19 2020 at 16:33, on Zulip):

we never store false into the poison flag after setting it

RalfJ (Apr 19 2020 at 16:34, on Zulip):

hm. I guess there is no guarantee that the unlock indeed restored the invariant

RalfJ (Apr 19 2020 at 16:34, on Zulip):

so maybe it should be explicit

simulacrum (Apr 19 2020 at 16:34, on Zulip):

yeah -- we could provide a clear() on the mutexguard

simulacrum (Apr 19 2020 at 16:35, on Zulip):

I'm not sure how useful that would be given that poisoning is generally questionably useful anyway :)

simulacrum (Apr 19 2020 at 16:36, on Zulip):

at least in the code I've written I either don't care (and so always do the unwrap_or_else(|e| e.into_guard()) dance) or just unwrap

bjorn3 (Apr 19 2020 at 16:36, on Zulip):

It is very useful. Otherwise the main thread would likely continue after an unexpected panic of a background thread.

simulacrum (Apr 19 2020 at 16:37, on Zulip):

Hm, well, I mean, I guess it can be useful

simulacrum (Apr 19 2020 at 16:37, on Zulip):

but I'm just saying that it's not obvious that Mutex in std should enforce it

simulacrum (Apr 19 2020 at 16:38, on Zulip):

anyway I'd be unopposed to providing a clear_poison function or so

bjorn3 (Apr 19 2020 at 16:38, on Zulip):

If std::sync::Mutex doesn't implement poison, it is very likely that most people won't bother to implement something to stop the program when a background thread panics.

bjorn3 (Apr 19 2020 at 16:38, on Zulip):

simulacrum said:

anyway I'd be unopposed to providing a clear_poison function or so

me neither

nagisa (Apr 19 2020 at 19:47, on Zulip):

Its not necessarily true that just ignoring poison makes the data actually valid.

nagisa (Apr 19 2020 at 19:47, on Zulip):

e.g. things like a print routine doesn’t actually care if a structure is half updated, but an algorithm might

Last update: May 29 2020 at 17:55UTC