Fix detach call and adjsuted destructor

Release the pointer to the stack and set the handle to uninitialized,
also don't decrement the stack count if thread object is destroy, but
does not hold a handle to a valid thread.