fix Issue 10976 - thread_joinAll after main exit performed too late

- Move thread_joinAll out of rt_term and call it
  immediately after exiting from main instead.
- Make it an error to call rt_term when other threads
  are still running.
- It was not a good idea to call thread_joinAll in rt_term
  because with DLLs threads could have been attached and
  outlive the runtime.
- As a side effect it will be called before `static ~this()`
  of the main thread is run.