Hi I have a server which creates a new detached pthread every time it accepts a new connection. Inside such a thread an object is created which modifies a std:vector. At the end of the program, long after the connection has terminated, and very probably after the thread has finished, said object is deleted.
Now helgrind makes messages such as ==18078== Possible data race during read of size 4 at 0x4330b98 by thread #1 ==18078== at 0x804C9A4: std::_Deque_iterator<std::string, std::string&, std::string*>::_Deque_iterator(std::_Deque_iterator<std::string, std::string&, std::string*> const&) (stl_deque.h:131) ==18078== by 0x804D15B: std::deque<std::string, std::allocator<std::string> >::~deque() (stl_deque.h:725) ==18078== by 0x804C64D: LineBuffer::~LineBuffer() (LineBuffer.cpp:21) ==18078== by 0x8049FC2: OutBuffer::~OutBuffer() (OutBuffer.cpp:28) ==18078== by 0x8049205: main (in /home/jody/progs/outputredir/OCTest) ==18078== This conflicts with a previous write of size 4 by thread #3 ==18078== at 0x804D83F: std::deque<std::string, std::allocator<std::string> >::push_back(std::string const&) (stl_deque.h:1042) ==18078== by 0x804C744: LineBuffer::addLine(char*) (LineBuffer.cpp:28) ==18078== by 0x80495F2: OutputCollector::threadStart(void*) (OutputCollector.cpp:197) ==18078== by 0x40099BA: mythread_wrapper (hg_intercepts.c:194) ==18078== by 0xB0950A: start_thread (in /lib/libpthread-2.7.so) ==18078== by 0xA4AB2D: clone (in /lib/libc-2.7.so) I have fixed that by inserting mutexes: pthread_mutex_t lxlx; LineBuffer::~LineBuffer() { // (helgrind) this mutex is necessary and must be the same as the one below pthread_mutex_lock(&lxlx); pthread_mutex_unlock(&lxlx); } void LineBuffer::addLine(char *pLine) { // (helgrind) this mutex is necessary and must be the same as the one above pthread_mutex_lock(&lxlx); if (m_vLines.size() >= m_iMaxLines) { m_vLines.pop_front(); } m_vLines.push_back(pLine); m_pObs->handleNewLine(m_iIndex, pLine); pthread_mutex_unlock(&lxlx); // notify observer } My question is: has there really been a data race, or did valgrind only decide that if the timing is right, there could be a data race? >From the way i see it, there could not have been a real data race... Thank You Jody ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users