You need to restructure your code. Use an exit event as others have mentioned and inside the
Code:
some_function_that_takes_long_time();
function, frequently check if the exit event has been set. If it has return a false from the function, and exit the thread if the function has returned false.