If you want to be able to clean up after yourself on thread T1, a better answer would be to send yourself a signal from T2 (I've used the USR1 signal before), which would cause the select() call in T1 to return with a value of EINTR.
You could then check for EINTR and know that you needed some cleanup done and do it. In my case, I had a separate thread that was in an infinitely-blocked select() waiting for reading, in a while loop with an exit flag.
while ( !exit_flag )
{
...
int select_retval = select( ... );
switch ( select_retval )
{
case EINTR:
/* clean up */
break;
default:
break;
}
}
I would set the exit flag from T2 and then send the signal to T1. T1 would then clean up and then get out of the loop. In my case, the loop was the function running in T1, thus T1 would end.