Can we create nested workers instead of having this complex pattern where we involve the UI thread?
If that's possible, I'd also keep references for outputThread and t_ptr_S in server-thread context, in order to terminate the output thread and call handle_output_* from server-thread. 
I'd be really happy to get rid of runOnPeerThread that is too magical to my opinion and is often usages of the UI thread.