bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #33392] Multi-thread bug in NSObject retain and release


From: Jonathan Olson
Subject: Re: [bug #33392] Multi-thread bug in NSObject retain and release
Date: Wed, 25 May 2011 08:44:27 -0700

Richard,

I don't have a small example.  The application is a relatively large 
multi-threaded app server which supports a couple hundred TCP/IP sockets.  This 
typically crashed about every 30-60 minutes.

For x86, the fix could use the xaddl instruction which is an atomic exchange 
and increment instruction.  Note that the other architectures (mips, powerpc, 
68k) defined in NSObject.m all share the same bug, so you should fix these also.

Possibly, you can use a recent version of gcc to generate the instruction 
sequence for each CPU.  For example, compiling the following program generates 
the following for x86.

#include <stdio.h>

int
main(int argc, char **argv)
{
    int lock = 0;
    int lock1 = __sync_fetch_and_add(&lock, 1);
    int lock2 = __sync_fetch_and_sub(&lock, 1);
    fprintf(stderr, "lock = %d %d %d\n", lock, lock1, lock2);
    return 0;
}

_main:
LFB3:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
        subq    $16, %rsp
LCFI2:
        movl    $0, -4(%rbp)
        leaq    -4(%rbp), %rax
        movl    $1, %ecx
        lock
        xaddl   %ecx, (%rax)
        movl    $-1, %r8d
        lock
        xaddl   %r8d, (%rax)
        movl    -4(%rbp), %edx
        movq    address@hidden(%rip), %rax
        movq    (%rax), %rdi
        leaq    LC0(%rip), %rsi
        xorl    %eax, %eax
        call    _fprintf
        xorl    %eax, %eax
        leave
        ret

On May 25, 2011, at 2:32 AM, Richard Frith-Macdonald wrote:

> Update of bug #33392 (project gnustep):
> 
>                  Status:                    None => Fixed                  
>             Open/Closed:                    Open => In Test                
> 
>    _______________________________________________________
> 
> Follow-up Comment #1:
> 
> Thanks ... the window for the bug to occur must be small for it not to have
> shown up in testing before now.  Do you have a small test program to
> demonstrate it?
> 
> Anyway, after spending several hours research on he web I hope I've got the
> correct fix for this (I'm not at all familiar with x86 assembler though) and
> have added it to svn trunk.
> 
> Please could you try this latest code and let me know if it's correct.
> 
> 
>    _______________________________________________________
> 
> Reply to this item at:
> 
>  <http://savannah.gnu.org/bugs/?33392>
> 
> _______________________________________________
>  Message sent via/by Savannah
>  http://savannah.gnu.org/
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]