toot.cat is one of the many independent Mastodon servers you can use to participate in the fediverse.
On the internet, everyone knows you're a cat — and that's totally okay.

Administered by:

Server stats:

419
active users

Public

Never use Tokio mutexes. From a guide I'm in the middle of writing:

@rain ooof. I assume this applies to futures::lock::Mutex, too?...

Public

@zkat Yes, looks like it. Basically async and mutexes just don't play along, because futures can always be cancelled (dropped) at any await point

Public

@rain @zkat

Given a choice I'd reach for tokio's Mutex before futures::lock::Mutex -- they both have the same issue Rain describes (where if you drop them while invariants are violated, you get bugs later), but tokio's is at least fair (making starvation harder).

Public

@rain @zkat shouldn’t the drop of the task imply a drop of the mutexguard?

Public

@baloo @zkat Yes, the problem is that if invariants are violated in the middle of the critical section (very normal for mutexes) then the mutex silently unlocks and the invariants stay violated

Public

@rain @zkat ha, good point! I was only looking for poisoned mutex

Public

@rain @zkat removing the Unpin blanket implementation should make sure it can't cross await points right?

Public

@baloo @zkat That would defeat the point of tokio mutexes though, if you don't want to cross await points then you can just use std mutexes