Hi,
The answer from fpmurphy is short, but up to the point. Let me explain a little bit; In a multi-threaded process, a signal handler process-wide, that is global to all threads. However, when the signal is delivered, the system library / kernel picks up a particular thread that shall run the handler. This might be any thread in the process.
In your particular example, you wish that the handler runs in the context of thread1, so that the recvfrom() gets interrupted. But, unless you force it too, the handler may run in the context of the main thread. In that case, nothing will happen. This is likely what you are experiencing.
The way to force the handler to run in the context of thread1 (or equivalently, we say the signal to be delivered to thread1) is using pthread_sigmask() as mentioned by fpmurphy. Please refer to example in the link provided above, to see how it works. Incidentally, this example was my first contribution to the SUSv3 standard; so if you have questions please feel free to ask
And finally, I would suggest to resort other strategies than alarm() & co. to implement a timeout on the receive operation if you're multi-threaded.
Cheers, Loïc.