Closed martinradev closed 3 years ago
A solution would be to modify the API. Instead of keeping a global context stored in the library, the API could be extended so that ContextInit returns a context handle to the user. The context handle is to be passed to the compress/decompress functions. The handle can additionally be bound to a mutex so that within the implementation of the compress/decompress functions, the mutex is acquired. This achieves two things:
Hi, We fixed the thread-safe issue recently. Please check the github master branch. There are multiple error bound modes. Specifically, ABS (absolute error bound) and REL (value-range based error bound) is supposed to be thread safe now. fix-PSNR mode is still not thread safe. We added two example codes test_threadsafe.c and test_threadsafe2.c in the example/ directory.
Forgot to mention that the thread safe support is mainly provided for single-precision (float) and double-precision (double) in the current implementation.
Is the PSNR mode currently thread safe?
The compress and decompress functions are not thread-safe. The reason for this is that a global context
confparams_cpr
,confparams_dec
,exe_params
is modified via some of the calls. Example:I think it would be beneficial to guarantee that calling the compress/decompress is thread safe. Otherwise, the user would have to introduce a single lock for the compress / decompress paths which would lead to contention and kill multi-threaded performance.