Mercurial > hg > orthanc-wsi
comparison Applications/ApplicationToolbox.cpp @ 7:bc3ca410b765
Fix freeze if the target Orthanc is not accepting images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 Oct 2016 15:42:52 +0200 |
parents | 4a7a53257c7d |
children | 62adabb8c122 |
comparison
equal
deleted
inserted
replaced
6:d0108402e85c | 7:bc3ca410b765 |
---|---|
72 void Execute(Orthanc::BagOfTasks& tasks, | 72 void Execute(Orthanc::BagOfTasks& tasks, |
73 unsigned int threadsCount) | 73 unsigned int threadsCount) |
74 { | 74 { |
75 if (threadsCount > 1) | 75 if (threadsCount > 1) |
76 { | 76 { |
77 // Submit the tasks to a newly-created processor | |
77 LOG(WARNING) << "Running " << tasks.GetSize() << " tasks"; | 78 LOG(WARNING) << "Running " << tasks.GetSize() << " tasks"; |
78 LOG(WARNING) << "Using " << threadsCount << " threads for the computation"; | 79 LOG(WARNING) << "Using " << threadsCount << " threads for the computation"; |
79 Orthanc::BagOfTasksProcessor processor(threadsCount); | 80 Orthanc::BagOfTasksProcessor processor(threadsCount); |
80 std::auto_ptr<Orthanc::BagOfTasksProcessor::Handle> handle(processor.Submit(tasks)); | 81 std::auto_ptr<Orthanc::BagOfTasksProcessor::Handle> handle(processor.Submit(tasks)); |
81 | 82 |
83 // Start a thread to display the progress | |
82 bool done = false; | 84 bool done = false; |
83 boost::thread progress(PrintProgress, handle.get(), &done); | 85 boost::thread progress(PrintProgress, handle.get(), &done); |
84 | 86 |
85 if (handle->Join()) | 87 // Wait for the completion of the tasks |
88 bool success = handle->Join(); | |
89 | |
90 // Stop the progress-printing thread | |
91 done = true; | |
92 | |
93 if (progress.joinable()) | |
86 { | 94 { |
87 done = true; | 95 progress.join(); |
96 } | |
97 | |
98 if (success) | |
99 { | |
88 LOG(WARNING) << "All tasks have finished"; | 100 LOG(WARNING) << "All tasks have finished"; |
89 } | 101 } |
90 else | 102 else |
91 { | 103 { |
92 done = true; | |
93 LOG(ERROR) << "Error has occurred, aborting"; | 104 LOG(ERROR) << "Error has occurred, aborting"; |
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 105 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
95 } | |
96 | |
97 if (progress.joinable()) | |
98 { | |
99 progress.join(); | |
100 } | 106 } |
101 } | 107 } |
102 else | 108 else |
103 { | 109 { |
104 LOG(WARNING) << "Running " << tasks.GetSize() << " tasks without multithreading"; | 110 LOG(WARNING) << "Running " << tasks.GetSize() << " tasks without multithreading"; |