When I click the button I am trying to stop the thread and thus the video. For this i only set the "stopped" flag to true. This is flag is checked in the run method of the thread. So ideally it should not execute anything. But the thread stops in between the execution of run method. (this is weird, or atleast seems)!! It stops after applying the mutex lock to buffer. This way when m trying to release the buffers in the Unix it gives error.