LibRaw threading requirements.

I'm attempting to use the LibRaw C++ API in a macOS Objective-C application. The LibRaw calls are being made inside an Objective-C++ file (.mm). However, I'm running into consistent crashes when attempting to use LibRaw on a background (non main) thread.

Simply declare a new LibRaw variable is enough to cause a crash:

LibRaw processor;

However, if I first switch over to the main thread using GCD, then it doesn't crash.

dispatch_sync(dispatch_get_main_queue(), ^{
  LibRaw processor;

I'm a bit confused what LibRaw's requirements are with regards to threading. I can understand that a single LibRaw instance should not be shared across threads, but what are the requirements with regards to using a LibRaw instance on a single thread that happens to be a background thread?

In my use-case, I'm attempting to decode RAW files on a background thread before displaying them to the user on the main thread.

(I am using libraw.a 0.18.2 from the download page.)

Thank you.


What is stack size in (GCD)

What is stack size in (GCD) background threads?

LibRaw objects are large, you may need to allocate it dynamically to save stack space.

-- Alex Tutubalin

Oops, I didn't even think of

Oops, I didn't even think of that but, you're right. Allocating a new LibRaw object dynamically solves the problem. Thanks for the quick response and for your work on LibRaw.