Page MenuHomePhabricator

mbi log is not thread-safe
Closed, WontfixPublic


It seems that if a message is written to the mbi-log in a thread and a second thread also tries to write a message an error is shown and the program crashes.

Ways to reproduce:

  • Load QBall-Image: E130-Projekte\NeuroDiffusion\Phantomstudien\Interleaved_90_Small\Phan_3500_047_QA6.qbi
  • Select "Gibbs Tracking"-View
  • Check "Advanced Settings"
  • Set "Particle Weight to approx. 0.012
  • Set "Min. Lenght to 0mm
  • Start with "Start Tractography"

After a random time the error occurs. Mbi-Log shows two messages nested into each other. The error also occurs when using other qbi-images.

fehler1.png (309×479 px, 35 KB)

Event Timeline

Semms to be fixed with Alfreds soon to come merge.

Lets check again after this merge. Should only be a matter of days.

Some more details on this bug:

The three functions in mbilog.cpp are missing necessary thread safety mechanisms:


An example failing scenario is:

(1) At the beginning of main, write some logging output. This block of code in mbilog::DistributeToBackends will be triggered:

if(backends.empty() && (dummyBackend == NULL))
  dummyBackend = new mbilog::BackendCout();

(2) Register a backend:

mbilog::RegisterBackend(new mbilog::BackendCout());

(3) Spawn a bunch of threads (e.g. in an OMP-parallelized for loop) that all immediately write logging information. In mbilog::RegisterBackend more than one (usually) will the next block of code:

else if((backends.size()>1) && (dummyBackend != NULL))
  //if there was added another backend remove the dummy backend and delete it
  delete dummyBackend;
  dummyBackend = NULL;

Since access to the dummyBackend variable is not protected I get glibc double free crashes.

Note that access to the backends static variable also needs to be protected.

Should this 2-year-old bug maybe be a higher priority?

A readers/writer lock would be ideal for best performance, but ITK doesn't seem to provide one (at least not yet...). See this ongoing thread:

Updating target milestone to upcoming release

Writing messages to the mbi-log is thread-safe. The registration/unregistration of backends is not thread-safe, as explained above. To make it thread safe you have to add a mutex lock to the backend list. The problem is that the mbilog-module has no dependencies so far (and shall not get any). Therefore, we cannot use the ITK mutex.

In future versions we can use the C++11 mutex lock. At the moment we are not able to use it because of backwards compatibility. Once we are free of this limitation it will be fixed.

kislinsk claimed this task.
kislinsk added a project: Auto-closed.
kislinsk added a subscriber: kislinsk.

Hi there! 🙂

This task was auto-closed according to our Task Lifecycle Management.
Please follow this link for more information and don't forget that you are encouraged to reasonable re-open tasks to revive them. 🚑

Best wishes,
The MITK devs

kislinsk removed kislinsk as the assignee of this task.May 26 2020, 12:05 PM
kislinsk removed a subscriber: kislinsk.