devkitPro / libctru

Homebrew development library for Nintendo 3DS/Horizon OS user mode (Arm11)

Home Page:https://libctru.devkitpro.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lockup when calling gspWaitForAnyEvent() and gspWaitForVBlank() simultaneously from different threads

badda71 opened this issue · comments

When calling gspWaitForVBlank() and gspWaitForAnyEvent() from two differnet threads, sometimes my program locks. gdb shows that the lock occurs because both functions arbitrate on the same handle. The exact service calls where the program hangs are below:
thread 1, gspgpu.c, line 106:

svcArbitrateAddress(__sync_get_arbiter(), (u32)&gspLastEvent, ARBITRATION_WAIT_IF_LESS_THAN, 0, 0);

thread 2, synchronization.c, line 206:

svcArbitrateAddress(arbiter, (u32)event, ARBITRATION_WAIT_IF_LESS_THAN, 0, 0);

Is this a bug? If no, how can I work around that?

commented

Horizon OS address arbitratrion is meant to be used with a single handle and multiple addresses (in fact the resource limits Nintendo usually assigns to applications restrict the maximum number of address arbiters that can be created to a single one per app); so that's a red herring.

At some point I intend to revise how GSP event handling works, since it's messy code right now. Doing that may have the side effect of fixing potential synchronization bugs.

With that said, applications are only really meant to do graphics processing from a single thread.