Refactor thread destruction logic
Refactor thread destruction logic

This patch refactors the thread object destruction logic to always
maintain a reference in the thread which is destroyed when the thread
exits.  Then if the thread is joinable, also add a reference which
is released when the thread is joined.

This change should have no effect in general, but works around some
RTOS platforms with non-existant or broken join logic.

Resolves: LE-16545
Change-Id: Ifd2c9f692b4f4fe0d20e40af9cb0afbe4c5678df

legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af,legatoproject/legato-af