• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: killing a sleeping server thread?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: killing a sleeping server thread?


  • Subject: Re: killing a sleeping server thread?
  • From: email@hidden (Sebastian Mecklenburg)
  • Date: Wed, 11 Jun 2003 22:29:53 +0200

hi,

On Wednesday, June 11, 2003, at 03:45 PM, Peter Sichel wrote:

The best way to kill a thread is for the thread to exit normally.
ah, ok. i thought there might be an acceptable way to abort a thread somehow.


Presumably in your case the server thread is waiting for something
such as network I/O or more specifically for a file descriptor to
become readable.
yes, network i/o, it waits for accept() to return.


What I do is use select() on both the file descriptor I want
to read from, and one end of a pipe. Then if I need to abort
the select(), I just write to the other end of the pipe.
hm, ok. i don't really understand that right now, but i think i have to look at that select() function a little bit closer then...

thanks a lot,
sebastian


- Peter

hello,

i have a question regarding client/server architectures in general and
pthreads in particular.
as i understood, a server usually loops in a thread, waiting for
clients to connect. in my case, when a a client connects, i want the
connection to be kept alive, because the server is gathering data (from
external sources (e.g. user input)) in irregular intervals which it
needs to pass on to the client. so i spawn a new thread for every
client, which retrieves the data to send from the server and sends it
on to the client. the individual threads are implemented as 'Monitor'
objects (see www.cs.wustl.edu/~schmidt/PDF/monitor.pdf), so if its
data-buffer is full the thread blocks until it sends something to a
client and if it is empty the thread blocks until there is some data
available again. the problem is, if one of the clients disconnects and
its server thread is blocked the server does not recognizes it, because
it rests in peace. so i started another thread that checkes frequently
if one of the clients has disconnected by checking getpeername() on the
associated socket descriptors. if getpeername returns -1, i know the
client has gone. that works fine but ... well, here i don't know what
to do. i would need to wake the blocked thread up and dispose of it.
now my questions are: how do i end that thread correctly? kill()?
detach()? is the client/server design i made up reasonable anyway?

regards,
sebastian mecklenburg




regards,
sebastian mecklenburg
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: killing a sleeping server thread? (From: "Peter Sichel" <email@hidden>)

  • Prev by Date: Re: NKE.pdf
  • Next by Date: Re: NKE.pdf
  • Previous by thread: Re: killing a sleeping server thread?
  • Next by thread: CFStream: Error handling problem
  • Index(es):
    • Date
    • Thread