4
votes

I have a Scala/Java OpenGL application in which I use the Akka framework. At the moment, my OpenGL thread is independent from the actor system so I can guarantee calls to OpenGL functions always come from a single thread. This is important, otherwise OpenGL will complain.

Until now, I had to send messages from the OpenGL thread to actors in the system and this works pretty well. I am now faced with the need to send messages the other way around, but of course I cannot simply put the OpenGL in an actor as this will break the requirement that it runs from a single thread.

An alternative would be to use a queue and a lock manually for the communication between actors and the OpenGL thread, but I'd like to know if there's a way to place OpenGL calls in a special Actor that would be given a guarantee by Akka to run in a single thread.

Regards

1
You can see how this is done for Swing (which requires all rendering work happen in Event Dispatch Thread)om-nom-nom

1 Answers

7
votes

You can use a single thread per actor using a PinnedDispatcher. According to the doc:

This dispatcher dedicates a unique thread for each actor using it; i.e. each actor will have its own thread pool with only one thread in the pool.