Changeset 766
- Timestamp:
- 06/25/08 14:13:17 (4 months ago)
- Files:
-
- trunk/phobos/internal/monitor.c (modified) (1 diff)
- trunk/phobos/std/synchro.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/internal/monitor.c
r295 r766 131 131 static pthread_mutexattr_t _monitors_attr; 132 132 133 pthread_mutexattr_t * _get_mutexattr() { return &_monitors_attr; } 134 133 135 void _STI_monitor_staticctor() 134 136 { trunk/phobos/std/synchro.d
r765 r766 132 132 private import std.c.linux.linuxextern; 133 133 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); 134 extern(C) { 135 pthread_mutexattr_t * _get_mutexattr(); 147 136 } 148 137 … … 152 141 this() 153 142 { 154 pthread_mutex_init(&_mtx, &monitors_attr);143 pthread_mutex_init(&_mtx, _get_mutexattr()); 155 144 } 156 145 ~this() … … 180 169 import std.synchro; 181 170 import std.thread; 182 183 Mutex mtx;171 import std.stdio; 172 184 173 int glob; 185 186 174 } 187 175 188 176 unittest 189 177 { 178 Mutex mtx = new Mutex; 179 190 180 void inc_glob_twice() 191 181 { … … 194 184 assert(glob % 2 == 0); 195 185 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 201 193 int f() 202 194 {
