Make IN-MAIN-THREAD safe for recursion