pthread: call dtors for pthread thread specific data

Use register_exit_notifier() to call dtors of thread specific data.

Right now, C++'s "thread_local" variable deconstruction relies on
pthread's task specific data management functions to work. So this
patch also fixes #373.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: add tests for pthread tsd related functions

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: remove abandon_current() call in thread::complete()

The application::abandon_current() call used to workaround the
thread_local deconstruction issue by explicitly deconstructing the current_app
variable.

This is no longer needed since thread_local deconstruction now works with the
previous patch. The variable will be deconstructed automatically when thread
exits.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
sched: adopt application in thread context

application::adopt() used to access other thread's thread_local variable
via remote_thread_local_var(). However c++'s thread_local variables are
initialized on first use, and compilers are not clever enough to
recognize
the indirect "use" through remote_thread_local_val(). So, the variable
is
not properly initialized before we access it.

Particularly, the deconstructor for 'current_app' is not registered to
be called when thread exits which shall be done during initialization.
This will cause the use_count of 'current_app' not decreasing after
thread
exits. As a result, the application pointed by 'current_app' is not
deleted.

This patch moves the call to adopt_current() in the thread context, so that
the thread_local are properly initialized. The 'app' to adopt is passed
via a lambda expression wrapping '_func'.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
app: remove application::adopt()

This function is no longer needed. Use adopt_current() in thread context
instead.

Signed-off-by: Zifei Tong <zifeitong@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>