Re: [Cppcms-users] Possible data race in lru at cache_storage.cpp?
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2015-04-10 16:01:29
|
Yes I'm familiar with Valgrind an exceptional tool. The code does not require to lock the LRU mutex - I'll explain. The cache storage is ALWAYS accessed via read-only (multiple lock) or write (unique lock access),for example in store() it is locked at line 354. However for read access which is vast majority multiple threads can access the cache. But LRU updatewith is rather a short part is write access to it has its own lock. Now read and write lock can't be hold simultaneously so LRU is already protected is store by higher level lock. In any case nice to see somebody actually goes as deep as that. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ From: Vinicius Pavanelli <ds...@ha...> To: cpp...@li... Sent: Thursday, April 9, 2015 5:45 PM Subject: [Cppcms-users] Possible data race in lru at cache_storage.cpp? Hi! I was testing my app with valgrind/helgrind and found some possible data race in cache_storage.cpp, i'm using version 1.0.5, and the code from lines 259-264 locks the lru_mutex fine, but later on in lines 374-375 there is some write to lru without a mutex to lock, there is a lock on access_lock but none in lru_mutex. Helgrind detected this as a possible data race, after i change the lines 374-375, following is a diff to it: --- cache_storage.cpp 2015-04-09 12:35:57.410064598 -0300 +++ cache_storage.cpp.fixed 2015-04-09 12:36:08.516731747 -0300 @@ -371,8 +371,11 @@ cont.generation=*gen; else cont.generation=generation++; - lru.push_front(main); - cont.lru=lru.begin(); + { + lock_guard lock(*lru_mutex); + lru.push_front(main); + cont.lru=lru.begin(); + } cont.timeout=timeout.insert(std::pair<time_t,pointer>(timeout_in,main)); if(triggers_in.find(key)==triggers_in.end()){ cont.triggers.push_back(triggers.insert(std::pair<string_type,pointer>(int_key,main) Is this valid or just some false positive and I overreact it? Well, hope it helps in anyway, helgrind shows a lot of problems in mysql library and in shared_ptr/shared_count usage that I really think are falses but if needed can post them also. By the way, in just a few hours i found at least 3 bugs in my own code with valgrind tools, got to know it via CppCMS site, recommend to anyone check it. Thanks for your time! ------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF _______________________________________________ Cppcms-users mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppcms-users |