Fixes problem with ordering of calls to mysql_library_end (in main) and mysql_thread_end (in monitor thr).