Skip to content

Reintroduce static lock order enforcement #5204

@jimblandy

Description

@jimblandy

Since Arcanization, we've been running into deadlocks at a pretty regular pace. This week's update of wgpu in Firefox exposed two new deadlocks which @nical has debugged and posted fixes for.

Before Arcanization, wgpu-core had a somewhat obscure rigging of tokens and types and traits ("oh my") such that acquiring locks in the wrong order would be a compile-time error. It wasn't well-documented, and people generally found it hard to understand. Arcanization removed this rigging, to cheers and rejoicing --- and we immediately started running into deadlocks. Some were sorted out before arcanization landed, but we've continued to find them since.

We should consider adding this static scaffolding back in --- accompanied by good global documentation for wgpu-core's locking discipline, to provide an explanation we can point to when people are confused.

Note that wgpu-core's locks post-arcanization bear little resemblance to the ones we had before. Previously, the lock hierarchy corresponded to resource types: Buffer, BindGroup, Device, and so on. But now all Registrys' RwLocks are "leaf" locks - they're only held for short periods of time, without acquiring other locks (I think that's right), so they don't have interesting relationships with each other. Instead, we'll be establishing an ordering between the various fields of Device like life_tracker and temp_suspected.

We'll have to think carefully about how SnatchLock fits into the picture.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions