Menu

#28 SeaBreeze is not multi-thread safe with the OOI_DEBUG symbol enabled

3.0
open
douga
2017-03-17
2017-03-17
Paul Solt
No

Seabreeze libraries will randomly crash when changing integration times in a multithreaded environment.

Seabreeze build is enabling logging for certain platforms/configurations, but it is not threadsafe, and it causes crashes when multiple threads are attempting to read out data from sbapi_spectrometer_get_formatted_spectrum().

Configuration: Seabreze 3.0.11
Mac/Linux: Makefile is bad for ALL builds (Mac/Linux/MinGW-32/Cygwin-32)
Windows: VS 2013 Debug 64bit is bad

Solution:

1. Disable Logging in the supporting common.mk file (line 83)

# enable Logger (logging is not threadsafe)
# CFLAGS_BASE += -DOOI_DEBUG

2. Disable Logging in VS2013 for 64-bit Debug build, remove the symbol in Project Properties > C/C++ > Preprocessor > Preprocessor Definitions > Edit > Delete OOI_DEBUG

Our Usage:
We need to use multiple threads for reading spectrometers and using hardware triggering with our STS spectromters. We run into crashes when we need to alter the integration time sbapi_spectrometer_set_integration_time_micros(), where we have to trigger the spectrometers so that we can break out of the blocking read function call: sbapi_spectrometer_get_formatted_spectrum().

Randomly when triggering the spectrometers so that we can break out of the blocking function: sbapi_spectrometer_get_formatted_spectrum(), the program will crash relating to the ~Log() in Xcode/Visual Studio. See the attached screenshot.

Screenshot:
See the attached screenshot for a snapshot of the call stack.

1 Attachments

Discussion

  • Paul Solt

    Paul Solt - 2017-03-17
     
  • Paul Solt

    Paul Solt - 2017-03-17

    A quick fix is to disable the debug symbol in released versions.

    A better fix would be to make the logging code thread safe, it uses a static variable which I believe is part of the problem when it happens from multiple threads.

    I don't know if this is only specific to changing integratin times, but that is where we see it consistently. Sometimes it takes 1-30 cycles of changing integration times before we see the thread crash. The crash goes away when you disable this symbol and build the app with a non-debug logging libseabreeze.dylib or seabreeze.dll file on Mac/Win.

     

Log in to post a comment.