Monadic regional resource management with support for threads.