Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-15-2005, 09:28 AM   #1
Registered: Jul 2005
Location: india,coimbatore
Distribution: Fedora core 4
Posts: 85

Rep: Reputation: 15
how to send a signal to a thread

Hello all,
Iam working on an application which requires sending request over n/w to server and receiving responses from the server. I have a seperate user defined function in which i create a socket and all other stuff(bind , send to ,recvfrom), the socket i have created is a datagram , nonblocking socket i also have created a thread which will be pointing to a function which runs an infinite loop and keeps on doing the select() function on the socket to read data from the server if any received in the socket. I also have another user defined function in which i close the socket. My requirement is that when the control enters this function in which i close the socket i need to signal the function which is being pointed by the thread so that it can exit the infinite loop. I tried a google but could not find any solution. If anyone has worked on these lines or have any idea abt how this cud be done i request ur goodselves to help me in this problem

Suresh stephen
Old 10-16-2005, 01:56 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
In general, I'd suggest setting a global variable.

In this case, why not use a pipe to signal the thread?

Since you're already blocking on "select()" (a good choice, rather than polling, BTW!), you might want to open a dummy file (e.g. a pipe), add that pipe to your "select()" FD_SET list, and then have the thread that closes the socket "signal" the reader thread by writing to the pipe. Voila!

I don't think there's any way to use a true "signal" (e.g. SIGUSER) here...
Old 10-17-2005, 01:07 AM   #3
Registered: Jul 2005
Location: india,coimbatore
Distribution: Fedora core 4
Posts: 85

Original Poster
Rep: Reputation: 15
hello paulsm4,
Thanks very much for ur reply It seems to be a gr8 idea , i will try it and see if it works.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel thread and signal handling oriate Linux - General 3 10-18-2005 12:41 PM
trying to send signal from linux module andreiij Programming 1 05-02-2005 12:46 PM
Has anyone can give an example about using signal in thread? xhhuango Programming 2 09-15-2004 08:10 PM
sending signal to thread waiting on pselect exedx Programming 4 03-21-2004 11:48 PM
send parameter from thread to thread marek Programming 2 09-08-2003 05:33 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration