Adds missing synchronization on reads of tsd->synch_perm in thread_synch_state_no_xfer() and thread_synch_check_state(), using a trylock to avoid hanging on a suspended thread that holds tsd->synch_lock. On trylock failure, both routines fail, which then prevents unsafe signal delivery.
TODO: try to create a test that reproduces the hang: it will not be easy and if it's not reliable it's not clear how much effort to put into it...
Fixes #2805 (closed)