Re: CFSocket callbacks and thread-safety
Re: CFSocket callbacks and thread-safety
- Subject: Re: CFSocket callbacks and thread-safety
- From: David Aames <email@hidden>
- Date: Mon, 12 Jun 2006 18:19:14 +0100
On 12 Jun 2006, at 18:12, Becky Willrich wrote:
It's fine to have several CFSockets share the same callback;
whether this means the callbacks will only be called sequentially
depends on how the CFSockets are scheduled. You schedule a
CFSocket by asking for its run loop source, and then installing
that run loop source on a run loop.
So suppose you have two CFSockets, you give them both the same
callback, and you schedule them both on the same run loop, in the
same mode. Then your callback will only be called from that one
run loop, which means that the callback for socket A will never be
triggered while you're in the middle of the callback for socket B -
the run loop can only be in one callback at a time. Now suppose
you schedule one socket on run loop 1 and the other socket on run
loop 2. If both run loops are running at the same time (the normal
case, since there's almost always exactly one run loop per thread,
and each thread runs its own run loop). Now both socket A and
socket B can be in their callback at the same time - socket A is
triggered by run loop 1, while socket B is triggered by run loop 2.
Finally, suppose both sockets are on the same run loop, but in
different modes. Now only one socket or the other can ever receive
its callback - the run loop can only run in one mode at a time, so
whichever socket is scheduled on the current mode will get its
callback, while the other one will never receive its (until the run
loop is run in the other mode).
In other words, it's the run loop and the scheduling that
determines which callback is sent when, not CFSocket. So your
regulator will need a thread lock if you schedule your sockets on
multiple run loops, all of which are running.
Clear as mud?
Perfect explanation, everything is now clear to me.
REW
On Jun 10, 2006, at 3:20 PM, David Aames wrote:
Hello all again,
I would like to ask someone who knows whether it is okay for
several CFSockets to be bound the same callback (are calls
queued?). Also my callback will be calling a regulator object
(which handles several sockets) and my concern is whether the
callback would call my regulator from another thread or in some
other non-serialized way (my regulator method is not thread-safe).
Should I be using a thread lock for my regulator?
Thanks
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden