Changeset 766

Show
Ignore:
Timestamp:
06/25/08 14:13:17 (4 months ago)
Author:
Bartosz
Message:

Re-entrant Mutex unit test passes on Linux

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/internal/monitor.c

    r295 r766  
    131131static pthread_mutexattr_t _monitors_attr; 
    132132 
     133pthread_mutexattr_t * _get_mutexattr() { return &_monitors_attr; } 
     134 
    133135void _STI_monitor_staticctor() 
    134136{ 
  • trunk/phobos/std/synchro.d

    r765 r766  
    132132private import std.c.linux.linuxextern; 
    133133 
    134 private pthread_mutexattr_t monitors_attr; 
    135  
    136 // Revisit: This should be called before static constructors, in case they start a thread 
    137 static this() 
    138 
    139     // Warning: this is non-portable 
    140     pthread_mutexattr_init(&monitors_attr); 
    141     pthread_mutexattr_settype(&monitors_attr, PTHREAD_MUTEX_RECURSIVE_NP); 
    142 
    143  
    144 static ~this() 
    145 
    146     pthread_mutexattr_destroy(&monitors_attr); 
     134extern(C) { 
     135    pthread_mutexattr_t * _get_mutexattr(); 
    147136} 
    148137 
     
    152141    this() 
    153142    { 
    154         pthread_mutex_init(&_mtx, &monitors_attr); 
     143        pthread_mutex_init(&_mtx, _get_mutexattr()); 
    155144    } 
    156145    ~this() 
     
    180169    import std.synchro; 
    181170    import std.thread; 
    182      
    183     Mutex mtx; 
     171    import std.stdio; 
     172     
    184173    int glob; 
    185      
    186174} 
    187175 
    188176unittest 
    189177{ 
     178    Mutex mtx = new Mutex; 
     179 
    190180    void inc_glob_twice() 
    191181    { 
     
    194184        assert(glob % 2 == 0); 
    195185        glob++; 
    196         glob++; 
    197     } 
    198      
    199     mtx = new Mutex; 
    200  
     186        { 
     187            // Test lock re-entrancy 
     188            scope lock2 = new Lock(mtx); 
     189            glob++; 
     190        } 
     191    } 
     192     
    201193    int f() 
    202194    {