The procedure is called when the thread is about termination. An application must execute all finalization code here.