0

I have got two programs written in c++ (to simplify it is A and B). A and B use ITK and A uses also Boost. I use the following procedure:

A calls B. B creates a file and writes into. Then A reads it.

Sometimes, B can't create the file and sometimes A can't read. But not always. I have tried to add a pre-step: A creates the file. But it doesnt change anything.

Have you ever heard about such behaviour? Do you have any idea?

A uses basic std::ifstream and B uses:

itk::TransformFileWriter::Pointer affineWriter;
  affineWriter = itk::TransformFileWriter::New();
  if( dofoutName != NULL )
  {
          affineWriter->SetFileName( dofoutName );
          affineWriter->SetInput( finalTransform   );
          affineWriter->Update();
  }
guhur
  • 2,500
  • 1
  • 23
  • 33
  • Can you be a bit more precise on the error you get? Does the file exist on the file system? Can you open it with notepad? Is maybe the file locked by another process sometimes? – lib Jul 17 '15 at 08:45
  • I get the error on my terminal: The process cannot access the file because it is being used by another process. This must come from my code extract. Yes I can open it with notepad. When I launch open A, it will work after. This isn't coming from my antivirus – guhur Jul 17 '15 at 13:05

1 Answers1

0

Maybe it is ifstream blocking it (see https://stackoverflow.com/a/750914/1136458 ). Check if the destructor of ifstream already called when you call B, or try not to use ifstream altogether.

If it's not enough and you are on Windows, you can debug your application, stop it and check on ProcessExplorer which handle is locking your file

Community
  • 1
  • 1
lib
  • 2,918
  • 3
  • 27
  • 53
  • Thanks ProcessExplorer is very great! – guhur Jul 17 '15 at 17:01
  • Yes, it is! What was the problem at the end, the code or something running in the system? – lib Jul 17 '15 at 17:14
  • the code was the problem. A is turned in parallel and each execution saves the output of B into the same file. This looks random because B is not always executed and A will crash only if A' uses B. – guhur Jul 18 '15 at 00:06