Fix stack overflow in sasmc error handler.
Introduce concept of threadid for each thread.