Author Topic: Single producer single consumer with no critical section locks  (Read 3054 times)

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
For those of you doing multithreaded programming, I wrote an article for Code Project on my implementation of a single producer single consumer that doesn't use critical section locks.  It is twice as fast as your typical implementation with locks.

http://www.codeproject.com/threads/SPSC.asp

Scorch

  • Jr. Member
  • **
  • Posts: 55
  • Karma: 2
    • View Profile
Re: Single producer single consumer with no critical section locks
« Reply #1 on: March 14, 2006, 11:53:42 PM »
I like your artical.
You could expand that to a que of objects/messages (effectivly when fail to lock for read or write object one try object two through n ... wraped into an object would look like a queue)

Also on your incrementing semephore example:
Code: [Select]
myType = spc.WriteUnlock();
myType->myData1=5;
myType = spc.WriteUnlock();
myType->myData1=6;
spc.WriteUnlock();
spc.WriteUnlock();

I think you ment for the first two to be locks and the last two to be unlocks? instead of all unlocks?

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: Single producer single consumer with no critical section locks
« Reply #2 on: March 15, 2006, 12:27:02 AM »
Yeah the first two are supposed to be locks.  It's a queue of structures essentially so you can put whatever you want into the queue.