gabr42 / OmniThreadLibrary

A simple and powerful multithreading library for Delphi
http://www.omnithreadlibrary.com
Other
466 stars 142 forks source link

TOmniMREW TryEnterWriteLock/TryEnterReadLock #151

Closed hsvandrew closed 4 years ago

hsvandrew commented 4 years ago

Are you sure the return value from this code is correct? I might be going crazy but I feel returnFalse should be set to "false" if result = true on the Timeout function and that this function never returns the correct return value of false...

gabr42 commented 4 years ago

Which wait function and under what condition, specifically? Result is set to False in the Timeout sub-function.

hsvandrew commented 4 years ago

TryEnterWriteLock/TryEnterReadLock should return FALSE if the lock could not be gained. Look through the code. I can't see how its possible for TryEnterWriteLock to ever return false.

hsvandrew commented 4 years ago

The result being set in the timeout function is for the inner Timeout function, not the outer TryLock function. It looks like returnFalse should be setting the outer result to false, but it doesn't....

gabr42 commented 4 years ago

This code fragment writes out FALSE.

var
  rw: TOmniMREW;

rw.EnterReadLock;
Writeln(rw.TryEnterWriteLock(100));

If you don't understand why, walk through the implementation in the debugger.

hsvandrew commented 4 years ago

Sorry to be confused, so line 1296 sets result = true; Which line sets result = false?

hsvandrew commented 4 years ago

This code fragment writes out FALSE.

var
  rw: TOmniMREW;

rw.EnterReadLock;
Writeln(rw.TryEnterWriteLock(100));

If you don't understand why, walk through the implementation in the debugger.

I agree this should return false, but in 3.07.7 it returns TRUE on 10.3.3

hsvandrew commented 4 years ago

image

hsvandrew commented 4 years ago

image

hsvandrew commented 4 years ago

Sorry! Didn't see this was fixed in .8 release