LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-15-2005, 09:28 AM   #1
stephenwalter
Member
 
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


Regards,
Suresh stephen
 
Old 10-16-2005, 01:56 AM   #2
paulsm4
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!

PS:
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
stephenwalter
Member
 
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.

Regards,
S.SureshStephen
 
  


Reply


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


All times are GMT -5. The time now is 03:45 PM.

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