Discussion:
multithreaded multidevice app problems
Bruce Clay
2012-04-27 02:19:26 UTC
Permalink
I apologize to those that subscribe to the forum on Nabble for the double post here. There seems to be more traffic here and I have not had any replies on Nabble

I am trying to update a application that I wrote a few years ago that used OpenAL. The original app provided a DIS network radio capability for a single user. I am trying to support up to 4 users on 4 USB headsets. The application is multi-threaded with each USB headset operating in a different thread. Each thread creates its own instance of OpenAL so it has it's own device and context. If I turn on a single channel everything works ok. If I turn on a second channel the first channel stops working and the second one starts working. When I turn off the seconed channel the first one does not start working until I turn it off then back on. In searching the web I found messages that said a process can only have one context. Does that apply to the whole process or should a thread act
ing with it's own instance of OpenAL and it's own headset work? One of the goals is to receive a single message from the network and have all 4 users hear the message at the same time.

Bruce
Chris Robinson
2012-04-27 03:31:15 UTC
Permalink
Post by Bruce Clay
In
searching the web I found messages that said a process can only have one
context. Does that apply to the whole process or should a thread acting
with it's own instance of OpenAL and it's own headset work?
Hi.

What do you mean by an "instance of OpenAL"? The one-active-context-per-
process restriction is based on the DLLs being called. If you're using the
same DLL but with multiple devices (whether that's OpenAL32.dll, wrap_oal.dll,
or whatever else), there can still only be one active context per process. If
you're somehow loading multiple separate DLLs (and not the same DLL multiple
times), then whichever DLL's functions you call is the one that will be
affected.

OpenAL Soft[1] has a cleaner way around this, though. It has a new-ish
extension called ALC_EXT_thread_local_context[2], which provides functions to
make a context active only on the calling thread, so each thread can have a
different context. You could create 4 devices for 4 separate headsets, 1
context from each device, and set each context as current on 4 separate
threads, then they'll all work independently.

[1] http://kcat.strangesoft.net/openal.html
[2] http://kcat.strangesoft.net/openal-extensions/EXT_thread_local_context.txt

Hope that helps. :)

Loading...