views:

75

answers:

1

I'm working on a library which implements the actor model on top of Grand Central Dispatch (specifically the C level API libdispatch). Basically a brief overview of my system is as such:

  • Communication happens between actors using messages
  • Multicast communication only (one actor to many actors)
  • Senders and receivers are decoupled from one another using a blackboard where messages are pushed to.
  • Messages are sent in the default queue asynchronously using dispatch_group_async() once a message gets pushed onto the blackboard.

I'm trying to implement futures in the language right now, so I've created a new type which holds some information:

  • A group of its own
  • The value being 'returned'

However, I have a problem since dispatch_block_t is of type void (^)(void) so it doesn't return anything. So my idea of in my future_new() function of setting up another group which can be used to execute a block returning a result, which I can store in my "value" member in my future_t structure, isn't going to work.

The rest of the futures implementation is very clear, except it all depends on being able to get the value into the future back from the actor, acting on the message.

When using the library, it would greatly reduce its usefulness if I had to ask users (and myself) to be aware when futures were going to be used by other parts of the system—It just isn't practical.

I'm wondering if anyone can think of a way around this?

A: 

Actually had Mike Ash's implementation pointed out to me, and as soon as I saw his initWithBlock: on MAFuture, I realized what I needed to do. Very much akin to what's done there, so I'll save the long winded response about how I'm doing it.

jer