Exit every thread at once with exit_group (231)
Call exit_group (231) instead of exit (60) so every thread ends at once; a GNU as 2.43 program on Linux 6.12 with the status check.
Linux has two exit system calls and they differ in scope. exit (60) ends only the calling thread, and the process lives on until its last thread is gone. exit_group (231) ends every thread in the process immediately and sets the process's exit status. The C library's _exit and exit use exit_group, and so should any assembly program that may have created threads. This GNU as 2.43 program exits with status 3 for the whole process.
.text
.globl _start
_start:
mov $231, %eax /* exit_group */
mov $3, %edi /* status */
syscall$ as exitgroup.s -o eg.o && ld eg.o -o eg && ./eg; echo $?
3For a single-threaded program the two behave the same, which is why the older number is the one most tutorials show. The difference appears when a thread calls exit: the process keeps running with one thread fewer, and the exit status is only reported after the last one leaves. The exit_group(2) manual page documents the call. Only the low 8 bits of the status reach the parent, so 256 would arrive as 0.