Thread safe version of ofUrlFileloader? (Of 9.0)

Is there a way to use some incarnation of ofUrlFileLoader (or something else) that is safe to use in different threads. So far I have used two approaches which both have problems (leading to crashes) primarily it seems because of statics in that class:

My specific use case is I spawn a bunch of threads to first load a file and then parse that file. Since the parsing needs to be done in a separate thread and

  1. Using ofSaveUrlTo(…) or any function which calls getFileLoader() for a singleton can cause problems if multiple threads call it. I can work around this by calling getFileLoader() [ via ofRemoveAllURLRequests] in the main thread before any worker threads are spawned. But this only fixes one problem.

  2. Creating a thread local ofUrlFileLoader and then calling .saveTo(…) fixes the above but also has a problem because of a static bool factoryLoaded. Again the workaround is to call ofRemoveAllURLRequests() in the main thread before any worker threads. But even if i do that my program crashes (only on exit thoguh in this case) while trying to lock some mutex in SSLManager::shutdown().

Is there anything I can do here short of removing the loading from my threads entirely?


1 Like

ofxHTTP has a multi-threaded download example using a task-manager approach.

It gives you results only during the update() loop, keeping everything in the main thread.

I tried ofxHTTP but I couldn’t build it on OF 0.9.0 nightly build. :frowning:

1 Like

Hi – did you use the develop branch of ofxHTTP? Only the develop versions of the addon (and its requirements) work with 0.9.0. As soon as 0.9.0 is released, I’ll tag the current versions and move everything over to 0.9.0 compatibility. Let me know if you can’t get develop compiled. I’m using it successfully now on projects and I’d like to fix any bugs that you find. Thanks!

1 Like