Guillaume Paris
Guillaume Paris

Reputation: 10537

heap corruption and mutex

I have a serious bug in an application, and I try to understand what is going on.. I have some logs just before the crash. I can't reproduce the bug simply.

the context :

Thread1:
void f()
{
    log(thread1_1)
    boost::lock_guard< boost::recursive_mutex > lock(mutexABC)
    log(thread1_2)
       -- eventually corruption heap could occur here
    log(thread1_3)
}

Thread2:
void f()
{
    log(thread2_1)
    boost::lock_guard< boost::recursive_mutex > lock(mutexABC)
       -- eventually corruption heap could occur here
    log(thread2_2)
}

In my logs (I am using LOG4CXX) I have the following sequence:

15:36:45,260  thread2_1
15:36:45,263  thread1_1
15:36:45,265  thread1_2
15:36:45,265  thread2_2

some GUI log thread3_*

15:36:45,276  //application crash
and no thread1_3 log before thread2_2!

How is it possible I log thread2_2 before thread1_3 ? A lock can be unlocked due to a heap corruption without the program crash, and a second thread can acquire this lock and execute some code brefore application crash ?

I am under windows 7. my C++ program turn in release mode with compiler optimization turn on.

Upvotes: 0

Views: 901

Answers (0)

Related Questions