vcos: cleanup dummy threads properly

If a thread created outside vcos_thread_create() gets a vcos
call (e.g. vcos_thread_at_exit), vcos creates a "dummy" thread
context so that other vcos functions will work.

Unfortunately, it wasn't hooking into pthreads to be arrange
to be called when the thread terminated, so none of the thread
termination happened: the dummy thread context was not called
and the thread at-exit functions were not called. This caused
memory to be leaked.

Use the destructor function that can be passed into
pthread_key_create() to get a callback when a thread exits,
and use this to do the dummy thread cleanup. Do not do
anything when a regular vcos thread exits (this is handled
separately).

Signed-off-by: Luke Diamand <luke@diamand.org>
Merge pull request #141 from luked99/vcos_memleak_fix

vcos: cleanup dummy threads properly