Thursday, April 17, 2008

Lock free communication channel

By taking advantage of existing Windows XP API such as InterlockedPushEntrySList and InterlockedPopEntrySList is possible to decouple data exchange in communication channel. That is very important in places where processing speed is crucial point. “An interlocked singly linked list eases the task of insertion and deletion from a linked list. Singly Linked Lists are implemented using a non-blocking algorithm to provide atomic synchronization, increase system performance, and avoid problems such as priority inversion and lock convoys.” Access to the Singly Linked Lists is synchronized on a multiprocessor system, and with no need of locking mechanism.

Writer’s thread will save data into Singly Linked Lists and assign unique ID to the package. Then reader’s thread will pick packages one by one, order them by ID, and store packages in a cache list.

The cache itself could be ignored when processing is interested only in latest package – real time data. Since InterlockedPopEntrySList could read packages in random order, is considered necessary after extracting all packages from a cache to find latest one.

Singly Linked Lists are straightforward to implement and use in 32-bit code.

No comments: