[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Openexr-devel] thread safety on OS X?
From: |
Florian Kainz |
Subject: |
Re: [Openexr-devel] thread safety on OS X? |
Date: |
Mon, 07 Feb 2005 19:57:15 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030314 |
Paul Miller wrote:
I ran into a difference in the way Windows and OS X 10.3 behave when
using OpenEXR functions from a thread.
First, is it permissable to open an EXR file in one thread and read it
in another? This seems to "work" on Windows, but crashes horribly on
Mac. I found out that if I moved the read code completely out of the
thread, it started working on Mac.
If anyone is interested, I'm using Qt's QThread class.
Is what I am doing technically allowed?
The IlmImf library is meant to be thread-safe, and except for
initialization (see Aristarkh Zagorodnikov's "OpenEXR thread safety"
message from Jan. 31, 2005), we don't know about any problems
related to multithreading. We do use OpenEXR in multithreaded
software here at ILM.
For the next release, we've added the following two paragraphs to
the documentation:
Except for inititialization, the IlmImf library is thread-safe
in the following sense: In a multithreaded application program,
multiple threads can concurrently read and write distinct OpenEXR
files, but multithreaded reading or writing of a single file
requires mutual exclusion. In other words, each thread can
independently create, use and destroy its own input and output
file objects, but if multiple threads share a single input or
output file object, then the application program must ensure
mutual exclusion between the threads during accesses to the
object.
Before any OpenEXR files can be read or written, the IlmImf
library must initialize some internal data structures that are
shared between threads. In order to ensure that initialization
happens in a thread-safe manner, a multithreaded application
program must call the Imf::staticInitialize() function before
accessing any other functions or classes in the IlmImf library.
In a single-threaded program initialization happens automatically;
it is not necessary to call Imf::staticInitialize().
Note that staticInitialize() is not accessible in the current release
of OpenEXR. You can work around this and call staticInitialize()
indirectly by creating and destroying a dummy Imf::Header object
during program startup:
int
main ()
{
{
Imf::Header dummy; // Constructor calls Imf::staticInitialize()
}
... // start threads, do multithreaded work
}