stream->thread = NULL;  should go here instead