Fix bug when checking shell variable.
Spawn a thread if HAVE_CXX_THREAD or run the monitor on the caller's thread.