Intuition Layer Locking and Deadlocks

The single most important Intuition gotcha, from Heinz Wrobel's DevInfo/Intuition/ notes: Intuition deadlocks are usually caused by Layer-lock misunderstandings. Several Intuition functions take a Layer lock implicitly — most notably ObtainGIRPort() (undocumented in its autodoc) — and any synchronous Intuition call made while a Layer is locked can deadlock.

The rule

The LockLayer() autodoc carries this note, which governs the whole topic:

Further Note: while you hold the lock on a layer, Intuition will block on operations such as windowsizing, dragging, menus, and depth arranging windows in this layer's screen. It is recommended that YOU do not make Intuition function calls while the layer is locked.

Concretely: while Layers are locked (directly or transitively), you may not call Intuition and you may not wait on messages from Intuition. This applies to gadget and datatype authors in particular — "think about this hard when writing gadgets or datatypes!"

ObtainGIRPort() takes a Layer lock

ObtainGIRPort() performs a layer lock even though its autodoc doesn't say so. The autodoc does say you may not cache the returned RastPort:

This function must be called EACH time a hook routine needing to perform gadget rendering is called, and must be accompanied by a corresponding call to ReleaseGIRPort().

That is a strong hint that you:

  • may use it only for simple rendering calls (that is what the function is for), and
  • may not yield control back to Intuition — by leaving the context or by calling Intuition functions — before calling ReleaseGIRPort().

Why "NewObtainGIRPort" patches are the wrong fix

The NewObtainGIRPort hack (and equivalent OS patches) is called out as both useless (the 1.1 code is buggy and doesn't really fix anything) and wrong-headed: the OS is fine; the application causing the problem should be fixed. Anyone shipping such a patch is papering over an app that violates the layer-locking rule above. Complain to the application's author, not the OS.

  • Don't do "atomic modifications" of shared Intuition structure fields (e.g. flipping WFLG_REPORTMOUSE via ReportMouse() bypass). On PowerPC a single instruction may no longer be atomic — if there's an API to mutate a shared value, use it.
  • Some Intuition paths still lack proper semaphore protection (see the CloseWindow() / CloseWindowSafely() autodoc). Expect Forbid()-style locking to be replaced by real semaphores in a PowerPC OS; isolate those code regions now to ease the port.
  • Don't "play stunts with the borders" — adding gadgets to borders relied on metrics you could only get by hacking internals. Expect a real API for window metrics in a future OS; the GUI will change.

See Also


Sources: Heinz Wrobel, Amiga Technologies, DevInfo/Intuition notes (1996). Raw: raw/intuition/layer-locking.md Updated: 2026-08-04