[Openal-devel] Thread-local contexts

Chris Robinson chris.kcat at gmail.com
Wed Sep 9 15:11:57 PDT 2009


My current thinking is to have two new functions.

alcMakeThreadCurrent - Sets a thread-specific context, which overrides the
    process-wide context when set to a non-NULL value. If non-NULL,
    alcGetCurrentContext will return this context when called from the
    corresponding thread, otherwise it will return the process-wide context.

alcGetThreadContext - Returns the current thread-specific context, or NULL if
    one is not set. Unlike alcGetCurrentContext, this will not return the
    process-wide context if no thread-specific context is set.

The second function is needed in case some code wants to set, then later 
restore, the proper context for a thread. Since alcGetCurrentContext will give 
the context that currently affects the given thread, it won't say whether this 
context is process-wide or thread-local. Eg, doing:

oldctx = alcGetCurrentContext();
alcMakeThreadCurrent(myctx);
...
alcMakeThreadCurrent(oldctx);

could make a process-wide context current for the thread (and subsequently 
won't change if alcMakeContextCurrent is later called), while doing:

alcMakeThreadCurrent(myctx);
...
alcMakeThreadCurrent(NULL);

could undo a thread-specific context the app may have set. So to fix this, you 
would do:

oldctx = alcGetThreadContext();
alcMakeThreadCurrent(myctx);
...
alcMakeThreadCurrent(oldctx);

which would properly restore the thread-specific context the app expects.


More information about the Openal-devel mailing list