Comment #19 on issue 18488 by timurrrr: Possible data race on  
HistoryAddPageArgs
http://code.google.com/p/chromium/issues/detail?id=18488

Consider two threads running the same code (counter is a shared variable,  
initially
set to 0):

void ThreadProc() {
   for (int i = 0; i < 100000; i++)
     counter++;
}

experiments show that counter becomes 19XXXX, not 200000.

Now consider a data race on reference counter.
If two increments or decrements happen simultaneously, the reference  
counter may
become +1 or -1 to the correct value.
In case of "+1", we are unlikely to achieve zero refcount at all, so we are  
likely to
have a memory leak.
In case of "-1", reference counter may become zero more than once; and it  
can also
become -1.

For example, consider the following interleaving (T1, T2 = thread{1,2})
T1|T2| refcount
XXXXX|  0
++|  |  1
++|++|!!2, not 3!!
--|  |  1, not 2
   |--|  0, not 1   -> free is called
++|  |  1, not 2
--|  |  0, not 1   -> free is called the second time
--|  | -1, not 0

Please note that there is an equal number of "++" and "--" in this  
interleaving

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
Automated mail from issue updates at http://crbug.com/
Subscription options: http://groups.google.com/group/chromium-bugs
-~----------~----~----~----~------~----~------~--~---

Reply via email to