I’m using ITK 5.0.0, I use itk::FileOutputWindow to log the warning messages by

typedef itk::FileOutputWindow myFileOutputWindow;
myFileOutputWindow::Pointer window = myFileOutputWindow::New();

There are multiple threads in the program, each thread owns a FileOutputWindow object sharing the same log file.

  • Will it be a problem if many threads are writing log at the same time?
  • What if there are multiple instances of the same program executed at the same time, by same or different user
  • What if different users execute the same program and some of them may not have permission to write the file?


Each thread should not have its own instance of FileOutputWindow. You should have once instance and use it from all threads. This should work. Multiple instances of the program will probably not be able to write to the same file, which is normal. If a user does not have permission to write to a file, it will obviously not work.

Thanks for the clear reply!
I have one more question, could my wrong usage of the FileOutputWindow lead to crash?
I’m currently debugging a crash issue and the dump shows that it crashes at the destructor of FileOutputWindow. by access violation error. But I’m not able to reproduce it yet.
So I would like to ask your professional opinion qpjon it.
Thank you!

Yes - you need to keep at least one strong reference to it, or it will go out of scope and deallocate itself before you are done with it. I recommend keeping references to it using smart pointers (FileOutputWindow::Pointer) instead of plain pointers.

But I didn’t catch the point.
In each of my thread, when the FileOutputWindow deallocate itself, the thread have finished using the itk functions. So I’m done with it.
Is the problem due to all thread using different FileOutputWindow but output to the same file? Maybe they will share something internally?
I have tested one thread terminates before other thread write other logs, it seems ok.

Yes, I think that is a problem. You need one FileOutputWindow, and all threads use it.

1 Like

I see. Thank you so much!

1 Like