Monday, July 07, 2008

OmniThreadLibrary lock-free communication

image image I've updated the OtlComm.pas unit in OTL home page with a lock-free circular buffer, donnated by a fellow Slovenian Delphi programmer who goes by a nick 'GJ'.

This code is doubly-work-in-progress! I haven't even test it. It is disabled by default and you have to define conditional symbol LockFreeBuffer to use it.

If you'll be making any comparisons to my original communication code and especially if you find any problem with new code, let me know.

UPDATE: I decided to use OTL_LockFreeBuffer instead of LockFreeBuffer. Repository has been updated, too.

6 comments:

  1. Anonymous20:58

    Nice project.
    There are a few issues (as expected given it's development state :o)

    The DPRs are missing in the test files, but that is a minor.

    I tried to build examples 3 4 5 6 and they all fail after 10-15 messages in TOmniRingBuffer.Dequeue. (I think it happens in
    Result := orbBuffer[orbTail];

    I haven't digged more into it than this (yet :o)

    Anyways, keep up the good work.

    Call stack :
    OtlComm.TOmniRingBuffer.Dequeue
    OtlComm.TOmniCommunicationEndpoint.Receive($12FCF8)
    OtlComm.TOmniCommunicationEndpoint.Receive(18,Unassigned)
    testOmniThreadLibrary1.TfrmTestOTL.OmniTaskEventDispatch1TaskMessage(TOmniTaskControl($AC65F8) as IOmniTaskControl)
    OtlTaskEvents.TOmniTaskEventDispatch.WndProc((49724, 7, 0, 1244852, 7, 0, 0, 0, 65204, 18))
    DSiWin32.DSiClassWndProc(???,???,???,0)
    :7e418734 USER32.GetDC + 0x6d
    :7e418816 ; C:\WINDOWS\system32\USER32.dll
    :7e4189cd ; C:\WINDOWS\system32\USER32.dll
    :7e4196c7 USER32.DispatchMessageA + 0xf

    ReplyDelete
  2. DPRs are included in the repository but were missed from the snapshots. Fixed, thanks for the notice.

    As for the lock-free problems, I'v notified the author of the code. Thanks for that report, too!

    ReplyDelete
  3. By the way - does your problem occur with lock-free buffer or with locking buffer? IOW, did you define OTL_LockFreeBuffer when compiling test?

    ReplyDelete
  4. I can see the problem and it occurs in my original Dequeue code.

    It's kinda hard to repeat here, but I'll fix it ASAP.

    ReplyDelete
  5. There seems to be a bug in the SpinLock code. As a temporary solution, I've reverted spinlocks into critical sections in the OtlComm code. The change has been uploaded to the repository. New snapshot is not yet available.

    ReplyDelete
  6. Anonymous14:11

    IOW, did you define OTL_LockFreeBuffer when compiling test?

    As you alreday found out : No. I just used the snapshot directly.

    This was fixed when i downloaded from SVN later on. Thanks.

    I follow your project with great interrest when time allows.

    I am looking forward to take a look at the latest stuff.

    ReplyDelete