[runtime] Move the thread exit code to mono-threads from io-layer.