12-19-2010
Quote:
Originally Posted by
Loic Domaigne
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.
Thanks, I will try it today.
9 More Discussions You Might Find Interesting
1. Post Here to Contact Site Administrators and Moderators
I am unable to open the mimesender thread. I get the following message when clicking on https://www.unix.com/showthread.php?p=33233#post33233 : (2 Replies)
Discussion started by: dangral
2 Replies
2. IP Networking
Hi
I want a UDP client receiving program. Here is the scenario. The client has to listen to the UDP server and has to acknowledge back on receiving data from the server. Can anyone help me out.
regards,
Nirmala (1 Reply)
Discussion started by: Nirmala
1 Replies
3. Programming
Hi,
Am very new to socket programming.
When we use UDP sockets to communicate between two processess,
will both the client/server socket be able to send/recv ?
meaning can sendto()/ recvfrom() be used on both server and client?
It could be useful even if anybody provide some link on socket... (1 Reply)
Discussion started by: rvan
1 Replies
4. UNIX for Advanced & Expert Users
HI
I want to create a UDP concurrent server
can any one give the code for UDP concurrent server (8 Replies)
Discussion started by: chanikya
8 Replies
5. Forum Support Area for Unregistered Users & Account Problems
Hello,
I'd like to post a aix thread but I'm unable to.
Please let me know why this is happening.
Thanks.... (1 Reply)
Discussion started by: sullivjp
1 Replies
6. Programming
Hi,
I have a situation where i need to communicate a linux client with a windows server, I am using a UDP socket communication channel. I am able to send packets from my linux clients to the windows server but unable to receive any data packet from the server. Do i need to make any setting in... (0 Replies)
Discussion started by: John20
0 Replies
7. IP Networking
Hifriends
I have a doubt .
how to create a multi-chat server using UDP which can run on MAC systems..
Thank u in advance (3 Replies)
Discussion started by: babbu25
3 Replies
8. Forum Support Area for Unregistered Users & Account Problems
I am unable to post reply to a thread. Whenever I will reply to any post I get the message every time :
The message you have entered is too short. Please lengthen your message to at least 5 characters.
Even though length of the message is more than required.
for example I tried to post
... (3 Replies)
Discussion started by: Unregistered
3 Replies
9. Forum Support Area for Unregistered Users & Account Problems
Hi.
I registered, but when trying to post, I get ...
"Sorry, you do not have enough Bits to post a new thread"
Google & Forum search showed some hits, but no solution.
Please advide.
Thanks! (1 Reply)
Discussion started by: gehe
1 Replies
LEARN ABOUT LINUX
pthread_kill
PTHREAD_KILL(3) Linux Programmer's Manual PTHREAD_KILL(3)
NAME
pthread_kill - send a signal to a thread
SYNOPSIS
#include <signal.h>
int pthread_kill(pthread_t thread, int sig);
Compile and link with -pthread.
DESCRIPTION
The pthread_kill() function sends the signal sig to thread, another thread in the same process as the caller. The signal is asynchronously
directed to thread.
If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a thread ID.
RETURN VALUE
On success, pthread_kill() returns 0; on error, it returns an error number, and no signal is sent.
ERRORS
ESRCH No thread with the ID thread could be found.
EINVAL An invalid signal was specified.
CONFORMING TO
POSIX.1-2001.
NOTES
Signal dispositions are process-wide: if a signal handler is installed, the handler will be invoked in the thread thread, but if the dispo-
sition of the signal is "stop", "continue", or "terminate", this action will affect the whole process.
SEE ALSO
kill(2) sigaction(2), sigpending(2), pthread_self(3), pthread_sigmask(3), raise(3), pthreads(7), signal(7)
COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-01-28 PTHREAD_KILL(3)