RE: pthreads and CF runloops (possibly slightly OT)
RE: pthreads and CF runloops (possibly slightly OT)
- Subject: RE: pthreads and CF runloops (possibly slightly OT)
- From: Philip Lukidis <email@hidden>
- Date: Thu, 10 Nov 2005 13:30:42 -0500
Hi Shawn, thanks for your reply. I'll answer inline.
Philip Lukidis
> -----Original Message-----
> From: Shawn Erickson [mailto:email@hidden]
> Sent: Thursday, November 10, 2005 12:35 PM
> To: Philip Lukidis
> Cc: email@hidden
> Subject: Re: pthreads and CF runloops (possibly slightly OT)
>
>
>
> On Nov 10, 2005, at 9:07 AM, Philip Lukidis wrote:
>
> > Is this true?
>
> To be honest I am not sure I understand that statement in the
> developer documentation... It may make sense to file a doc defect to
> get that statement better clarified, it is a little lose in
> terminology (I assume "your application's run loop" means your
> applications main thread's runloop).
>
> > When I create a pthread, is a new run loop created, and is
> > the pthread associated with it?
>
> Likely no because I believe they are created lazily but that is an
> implementation detail (one that I am guessing at myself).
>
Lazy creation is OK, as long as it is created when I ask for it via
CFRunLoopGetCurrent() (and it seems to be).
> > I ask this because I've done a simple (naive) test of outputting
> > the address of my main runloop, and then
> > outputting the address of a pthread runloop, and they are different.
>
> They should be different since they are different threads. Each
> thread can get its own runloop which is basically a thread
> local data
> structure.
>
Yes, I was hoping for them to be different. My initial understanding was
that no runloop would ever be created for pthreads, but thankfully this
is quite false.
> > I've also modified my simple daemon to receive client messages in
> > the created
> > pthread, which seems to work.
>
> Can you better explain how you did this so we can help make sure we
> (and you) understand things? I ask given the following question.
>
Well, instead of waiting for messages from main(), I did so from my
pthread, using CFRunLoopGetCurrent() in order to get the runloop. This
worked OK, and is what I was hoping for.
> > So the question is, are pthreads associated with a runloop,
> and, if
> > not, how
> > can I create a runloop and associate a pthread with it?
>
> In this case when running under your pthread simply use
> CFRunLoopGetCurrent() but if in Cocoa/Carbon use their API for
> runloops. Of course that only gets you a valid reference for the
> runloop associated with the current thread (possibly
> "creating" it if
> needed). To actually have the runloop do what it does you
> need to run
> it.
>
Yes, this is what my simple server app showed me.
> <http://developer.apple.com/documentation/CoreFoundation/Conceptual/
> CFRunLoops/Tasks/Running.html>
>
> -Shawn
>
Thanks for that link, I'll read up more about runloops.
Philip Lukidis
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden