www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reentrant Lock

reply Larry Cowan <Larry_member pathlink.com> writes:
module tester;
import std.c.stdio;
import locks.reentrantlock;

class LockedIndex {
private ReentrantLock rlock;
private uint index;
this(int begin) {
rlock = new ReentrantLock;
index = begin;
}
int current() {
return index;
}
int getIx() {
int retn;
printf("A\n");
rlock.lock(); // block until lock is available
printf("B\n");
retn = index++; 
if (retn >= 256*256)
retn = -1;
rlock.unlock(); // release the lock
return retn;
}
}

LockedIndex ixLock;

int main( char[][] args )
{
ixLock = new LockedIndex(42);

printf("begin   %d\n",ixLock.current());

for (int i=0; i < 10 ;i++)
printf("%d: %d\n",i,ixLock.getIx());

printf("Done.\n");
return 0;
}
------------------------------
prints:
begin   42
A
Error: Access Violation
------------------------------ What am I doing wrong?
Apr 07 2005
parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
 ------------------------------
 prints:
begin   42
A
Error: Access Violation
------------------------------ What am I doing wrong?
Looks like a the locks.lib is corrupt. When I rebuild locks.lib without -O passed to the compiler everything works fine. That would explain why my unittests passed when I last updated it. I have updated the zip file with a locks.lib built without -O and I'll try to narrow down the problem to post to D.bugs for Walter to ponder. -Ben
Apr 07 2005
parent Larry Cowan <Larry_member pathlink.com> writes:
Thanks.
-larry

In article <d33in9$2d6o$1 digitaldaemon.com>, Ben Hinkle says...
 ------------------------------
 prints:
begin   42
A
Error: Access Violation
------------------------------ What am I doing wrong?
Looks like a the locks.lib is corrupt. When I rebuild locks.lib without -O passed to the compiler everything works fine. That would explain why my unittests passed when I last updated it. I have updated the zip file with a locks.lib built without -O and I'll try to narrow down the problem to post to D.bugs for Walter to ponder. -Ben
Apr 07 2005