killing a sleeping server thread?
killing a sleeping server thread?
- Subject: killing a sleeping server thread?
- From: email@hidden (Sebastian Mecklenburg)
- Date: Mon, 9 Jun 2003 21:53:27 +0200
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.