Using OpenGL with Akka Actors: one-stream guarantee is used for a specific actor

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

So far, I have had to send messages from the OpenGL stream to actors on the system, and this works very well. Now I am faced with the need to send messages in a different way, but, of course, I can’t just put OpenGL in the actor, as this will violate the requirement that it be executed from one thread.

An alternative would be to use a queue and manual blocking for communication between participants and an OpenGL thread, but I would like to know if there is a way to place OpenGL calls in a special Actor, who will be given a guarantee from Akka to run in a single thread.

Hi

+4
source share
1 answer

You can use one thread for each actor with PinnedDispatcher. According to the document:

This dispatcher allocates a unique thread for each actor using it; that is, each actor will have its own thread pool with one thread per pool.

+7
source

All Articles