• 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: Run loops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run loops


  • Subject: Re: Run loops
  • From: Mike Laster <email@hidden>
  • Date: Fri, 05 Jul 2002 21:28:54 -0400

On 7/5/02 8:44 PM, "Douglas Davidson" <email@hidden> wrote:

> On Wednesday, July 3, 2002, at 02:41 PM, Mike Laster wrote:
>
>> How do I externally force a run loop to "wake up"?
>>
>> What I'm trying to do is have my server gracefully shutdown after
>> receiving
>> a SIGINT.
>
> Very few calls are async-signal-safe. I am told that send() and
> mach_msg() are among them. So, one approach would be to set up an
> appropriate run loop source (CFSocket, for a socket, or CFMachPort, for
> a Mach port) and message the underlying socket or Mach port from your
> signal handler. The Mach port approach probably has lower overhead,
> but you may be more familiar with the socket approach; socketpair() is
> useful for this sort of thing.

I ended up hacking together a "version 0" runloop source that uses a
dedicated thread to watch for the event, and a sig handler of:

void _signalHandler(int sig)
{
pthread_mutex_lock(&_signalMutex);
_pendingSignal = sig;
pthread_mutex_unlock(&_signalMutex);

pthread_cond_broadcast(&_signalCondition);
}

Which wakes the thread up, which in turn signals the run loop source.

This seems to work, but I don't like having that extra thread lying around.
I'm also not 100% sure pthread_* calls are async safe, though it seems to
work consistently.

I'd like to convert to a "type 1" approach, but am not sure about mach
messaging. I know I can't use NSMachPort since I can't reliablly use ObjC
from inside of a signal handler.

If I do the Mach port approach, can I do it without the extra thread? I'm
not sure if a thread cand send a message "to itself" so to speak. Where it
sends a message in the handler, and then receives it in the run loop.
_______________________________________________
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: Run loops
      • From: Douglas Davidson <email@hidden>
References: 
 >Re: Run loops (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: Run loops
  • Next by Date: Re: Run loops
  • Previous by thread: Re: Run loops
  • Next by thread: Re: Run loops
  • Index(es):
    • Date
    • Thread