• 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: "Peter Sichel" <email@hidden>
  • Date: Wed, 11 Jun 2003 09:45:11 -0400

The best way to kill a thread is for the thread to exit normally.

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.

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.

- 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
_______________________________________________
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.

  • Follow-Ups:
    • Re: killing a sleeping server thread?
      • From: email@hidden (Sebastian Mecklenburg)
References: 
 >killing a sleeping server thread? (From: email@hidden (Sebastian Mecklenburg))

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