Friday, July 11, 2008

OmniThreadLibrary goes lock-free

WiPWell, not complete OTL, just the messaging subsystem, but even that is quite some achievement. The ring buffer inside the OtlComm unit is now implemented with a help of a lock-free stack. Lock-free buffer is now a default. If you want to compile OtlComm with the locking buffer, define the OTL_LockingBuffer symbol.

Lock-free buffer did not improve communication subsystem speed much at the moment as the limiting factor is Delphi's Variant implementation but that will change. The collective mind behind the OTL is working on some interesting messaging ideas that will be much faster but will still keep most of the Variant flexibility and simplicity.

What I can promise even now is that there will be lock-free stack and lock-free ring buffer included in the OTL as standalone reusable data structures. Sounds useful?

2 comments:

  1. If you haven't yet, you should take a look at this Microsoft article: "Memory Models: Understand the Impact of Low-Lock Techniques in Multithreaded Apps".

    http://msdn.microsoft.com/en-us/magazine/cc163715.aspx

    The article is written from a .NET standpoint, but there's plenty of info about the CPU cache that would still apply in Delphi -- but you'd have to figure out what Delphi's memory model is, and what the volatile semantics are. It'd be worth checking your implementation against all the read- and write-reordering stuff he talks about, and making sure there aren't any gotchas waiting for you (and there are many gotchas when you try to do low-lock threading -- from reading your later articles, it looks like you've already found a few).

    ReplyDelete
  2. Yes, I saw that already. Sadly, the .NET world is soooo different from the Win32 that this stuff is completely irrelevant.

    ReplyDelete