Attached is a test program that tests the order in which synchronously triggered sigsegvs and pthread_kill() generated signals get delivered.

The test program triggers sigsegvs from a thread and tests whether the the sigsegv handler is invoked when the sigusr1 handler is already running. If that happens it exits with exit code 27. It seems that if the signal is sent by pthread_kill() and its signum is lower than that of sigsegv then it can be delivered before sigsegv. A normal kill does not seem to do this.

I would expect that no asynchronously generated signal (and here I include those sent by pthread_kill()) can overtake a sigsegv even if its signum is lower.