将OpenGL与Akka Actors一起使用:保证单个线程用于特定的actor [英] Using OpenGL with Akka Actors: guaranteeing a single thread is used for a specific actor

查看:224
本文介绍了将OpenGL与Akka Actors一起使用:保证单个线程用于特定的actor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Scala / Java OpenGL应用程序,我在其中使用Akka框架。目前,我的OpenGL线程独立于actor系统,因此我可以保证对OpenGL函数的调用始终来自单个线程。这很重要,否则OpenGL会抱怨。

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.

到目前为止,我不得不将OpenGL线程中的消息发送给系统中的actor,这非常有效。我现在面临着以相反的方式发送消息的需要,但当然我不能简单地将OpenGL放在一个actor中,因为这会破坏它从单个线程运行的要求。

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.

另一种方法是手动使用队列和锁来进行actor和OpenGL线程之间的通信,但是我想知道是否有办法将OpenGL调用放在一个特殊的Actor中。给予Akka保证在单个线程中运行。

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.

问候

推荐答案

您可以使用 PinnedDispatcher 为每个actor使用单个线程。根据文档:

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


这个调度程序为每个使用它的actor赋予一个唯一的线程;
,即每个actor都有自己的线程池,池中
只有一个线程。

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.

这篇关于将OpenGL与Akka Actors一起使用:保证单个线程用于特定的actor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆