Using OpenGL with Akka Actors: guaranteeing a sing

2019-05-08 18:48发布

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条回答
我想做一个坏孩纸
2楼-- · 2019-05-08 19:13

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.

查看更多
登录 后发表回答