views:

47

answers:

1

I encountered a bug that has me beat. Fortunately, I found a work around here (not necessary reading to answer this q) -

http://lists.apple.com/archives/quartz-dev/2009/Oct/msg00088.html

The problem is, I don't understand all of it. I am ok with the event taps etc, but I am supposed to 'set up a thread-safe queue) using MPQueue, add events to it pull them back off later.

Can anyone tell me what an MPQueue is, and how I create one - also how to add items and read/remove items? Google hasn't helped at all.

A: 

It's one of the Multiprocessing Services APIs.

… [A] message queue… can be used to notify (that is, send) and wait for (that is, receive) messages consisting of three pointer-sized values in a preemptively safe manner.

Peter Hosey
Thanks for the link. Having read the documentation I am a little clearer, but still don't know how to create a queue (an mpqueueid is required, or add/pop items as the workaround suggests.
Ben Packard
The function to create a queue is `MPCreateQueue` (exactly as you might have guessed). An `MPQueueID` is what it gives you to identify the queue it created; the function takes a pointer to the variable into which it should put the ID. (Most Carbon and Core Services functions work like this, which is the inverse of how Cocoa methods do things. Carbon and Core Services functions return the error code directly and anything else by reference, while Cocoa methods return an object directly or an error object by reference.)
Peter Hosey
Thanks - I can now create a queue but am not sure about the adding and processing events. It looks like it has something to do with MPNotifyQueue and MPWaitOnQueue, but I can't quite conceptualise the process from the documentation. Presumably something (a task maybe) waits on the key, and something else 'notifies' it - which then pops out the top item? Best guess.
Ben Packard
Oh I meant to also confirm my understanding of your explanation - so..MPQueueID queueID = NULL;MPCreateQueue(creates the queue, and stores the ID into queueID?
Ben Packard
Correct on both counts (as long as by “top item” you mean “first item to be put into the queue that's still there”).
Peter Hosey