From: Maxim Mamontov Date: Fri, 21 Jan 2011 15:57:35 +0000 (+0200) Subject: Усунуто проблему race conditions у rscriptd X-Git-Tag: 2.407-rc3~199 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/1ed49c21260edc5b40aa2d0d4b8486bc1928f21b Усунуто проблему race conditions у rscriptd --- diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index f6d77c96..aca5da44 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -333,9 +333,16 @@ return false; //----------------------------------------------------------------------------- void LISTENER::ProcessPending() { -printfd(__FILE__, "Pending data size: %d\n", pending.size()); -std::list::iterator it(pending.begin()); -while (it != pending.end()) +std::list localPending; + + { + STG_LOCKER lock(&mutex, __FILE__, __LINE__); + printfd(__FILE__, "Pending data size: %d\n", pending.size()); + localPending.swap(pending); + } + +std::list::iterator it(localPending.begin()); +while (it != localPending.end()) { std::vector::iterator uit( std::lower_bound( @@ -375,9 +382,7 @@ while (it != pending.end()) users.erase(uit); } } - - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - pending.erase(it++); + ++it; } } //-----------------------------------------------------------------------------