add explicit thread_term call to replace atexit

- When calling rt_init/rt_term from ELF's .ctors/.dtors section
  atexit runs before rt_term, which causes a crash because the
  thread locks are already destroyed.
Merge pull request #589 from dawgfoto/threadTermLocks

add explicit thread_term call to replace atexit