Re: Cheating a synchronous call on the main thread
Re: Cheating a synchronous call on the main thread
- Subject: Re: Cheating a synchronous call on the main thread
- From: Jack Brindle <email@hidden>
- Date: Tue, 30 Jun 2015 10:13:44 -0700
Well, actually not quite true. Pthreads has that mechanism with the join facility. I like pthreads (er.. did before I began to grok GCD), but personally have no use for pthread-join, and definitely don’t recommend its use, but it does exactly this - waits for another thread to exit before continuing. Pthreads have been in OS X for a very long time…
Now let me repeat. pthread_join is evil, bad, not to be used. There are much better ways of doing things, even in pthreads.
And definitely not to be used in the main thread…
- Jack Brindle
> On Jun 29, 2015, at 2:41 PM, Quincey Morris <email@hidden> wrote:
>
> On Jun 29, 2015, at 13:50 , Gavin Eadie <email@hidden> wrote:
>>
>> The main thread is not involved in the above, but the idea of an “asynchronous-that-waits” == “apparently synchronous” call is demonstrated.
>
> Yes, but you achieved that by blocking a background thread. It works because you don’t care that the thread is blocked.
>
> Incidentally, this sort of thing will break GCD. If the background thread was allocated to your block by GCD and it blocks, GCD will start another thread to do the next thing in the same queue. In a situation where this can happen repeatedly, you can end up with unlimited numbers of threads in flight simultaneously — unlimited until the system crashes, that is.
>
> OS X (and iOS) have *never* had a thread “yield” mechanism other than returning to the main event loop. That means that your only valid reply to the code’s author is, “There’s no way to do what you want.”
>
> The only exception to this statement — one that it’s really a bad idea to even present, since it reflects old-fashioned Cocoa design principles from the 1980s — is the idea of running the run loop modally, which is what buttons (e.g.) do when you click on them.
>
> But the real question is, what is the downside of re-factoring the code in the way Jens suggested? Has the code author tried? That’s what’s frustrating — after all this discussion, there’s a good chance that re-factoring will fall out problem-free with about 5 minutes of effort.
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden