Mercurial > hg > orthanc
comparison Core/MultiThreading/RunnableWorkersPool.cpp @ 2134:ddc75c6c712d
Avoid hard crash if not enough memory
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 12:04:09 +0100 |
parents | b1291df2f780 |
children | a3a65de1840f |
comparison
equal
deleted
inserted
replaced
2133:15ae532af70e | 2134:ddc75c6c712d |
---|---|
50 | 50 |
51 static void WorkerThread(Worker* that) | 51 static void WorkerThread(Worker* that) |
52 { | 52 { |
53 while (that->continue_) | 53 while (that->continue_) |
54 { | 54 { |
55 std::auto_ptr<IDynamicObject> obj(that->queue_.Dequeue(100)); | 55 try |
56 if (obj.get() != NULL) | |
57 { | 56 { |
58 try | 57 std::auto_ptr<IDynamicObject> obj(that->queue_.Dequeue(100)); |
58 if (obj.get() != NULL) | |
59 { | 59 { |
60 IRunnableBySteps& runnable = *dynamic_cast<IRunnableBySteps*>(obj.get()); | 60 IRunnableBySteps& runnable = *dynamic_cast<IRunnableBySteps*>(obj.get()); |
61 | 61 |
62 bool wishToContinue = runnable.Step(); | 62 bool wishToContinue = runnable.Step(); |
63 | 63 |
64 if (wishToContinue) | 64 if (wishToContinue) |
65 { | 65 { |
66 // The runnable wishes to continue, reinsert it at the beginning of the queue | 66 // The runnable wishes to continue, reinsert it at the beginning of the queue |
67 that->queue_.Enqueue(obj.release()); | 67 that->queue_.Enqueue(obj.release()); |
68 } | 68 } |
69 } | 69 } |
70 catch (OrthancException& e) | 70 } |
71 { | 71 catch (OrthancException& e) |
72 LOG(ERROR) << "Exception in a pool of working threads: " << e.What(); | 72 { |
73 } | 73 LOG(ERROR) << "Exception while handling some runnable object: " << e.What(); |
74 } | |
75 catch (std::bad_alloc&) | |
76 { | |
77 LOG(ERROR) << "Not enough memory to handle some runnable object"; | |
78 } | |
79 catch (...) | |
80 { | |
81 LOG(ERROR) << "Native exception while handling some runnable object"; | |
74 } | 82 } |
75 } | 83 } |
76 } | 84 } |
77 | 85 |
78 public: | 86 public: |