Re: Question on passing events to multithreaded OpenGL apps
Re: Question on passing events to multithreaded OpenGL apps
- Subject: Re: Question on passing events to multithreaded OpenGL apps
- From: Jens Alfke <email@hidden>
- Date: Sat, 01 Oct 2016 11:34:08 -0700
> On Sep 26, 2016, at 12:21 PM, John Richardson <email@hidden> wrote:
>
> There isn't anyway to tell OSX to give events to a thread other than the main one, the only way to handle it is to catch all the events in the main thread and pass them on to other threads to handle. It's a pretty frustrating limitation, no doubt you like many others, including myself have torn hair over this limitation, alas there it's futile, you just have to work how Apple wants you to write your applications even when it doesn't make much sense for certain type of applications.
(This is off-topic for xcode-users, but I’m answering it anyway…)
Yes, the main thread’s runloop includes the support for receiving events from the WindowServer process and dispatching them. That’s just how it works. It seems like a very reasonable design to me, so I’m surprised to hear someone railing against it as unreasonable.
The thing is, there is no general notion of “giving events to a thread”. In computer science a thread is just a CPU execution context that runs code independently of other threads until it stops or is killed. That’s it. The concept doesn’t include any notion of messaging between threads, nor do typical thread implementations like pthreads.
You can build an API for messaging between threads, on top of primitives like locks and queues, but obviously the threads involved have to agree on what API to use. The typical ones used on Apple platforms are kqueues and CFRunLoop (aka NSRunLoop.) But neither of these are known to OpenGL, and OpenGL-based code can’t be required to use these. So there’s no universal way to send events or other messages to a thread running OpenGL.
Even if there were such a messaging API, there’s no reasonable way for the source of events, the WindowServer process, to know which of those threads a particular event should be sent to. Presumably it would be based on things like hit-testing the scene graph, or a concept of what entity has “focus”. Those are very high level concepts specific to your app that the window server has absolutely no knowledge of.
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden