sched: run exit notifiers earlier, in thread context

We have an "exit notifiers" mechanism which can call a number of
registered functions whenever a thread exits. Before this patch,
these callbacks were only called at time of ~thread(), i.e., the time
of the join(). This patch makes them be called in complete() time,
immediately when the thread functions ends (or calls thread::exit()).

Because the callbacks are now called in the exiting thread's context,
the callbacks are simplified (no need for remotre_thread_local_var())
and are not called in an unknown thread with unknown stack limitations.

But more importantly, there are 3 subsystems which could have used
the exit notifiers mechanism but need it to be in complete().
One such place is our call to app->abandon_current() in complete()
which could have been an exit notifier. Second is the (uncommitted)
inherited tls patch. Third is the Zifei's pthread_key_create() patch,
which needs to run destructors when the thread ends (not when joined),
and in the context of this thread.

This patch also changes the mutual-exclusion scheme for the callback
list (which never changes after boot!). Instead of a global mutex,
we now use RCU which means that threads on different CPUs may exit in
parallel without causing unnecessary contention. Because the callbacks
may sleep, we can't run them in the RCU critical section, so we only make
a copy of the callback list in the RCU critical section. This technique
is fine as long as we don't support *removing* thread-exit callbacks -
which we currently don't support.

Tested-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>