Chris
Mon Aug 28 14:16:21 CDT 2006
I had access to a 16-process or Itanium Box, a 4 Processor Itanium box, a 2
Processor AMD machine, and my single processor laptop.
I took some time to run some locking / no-locking tests and came up with
surprising results. I keep meaning to write this up as a blog entry, but
unfortuantly I didn't to a thorough enough job of data capture.
On the 1 and 2 processor box, locking was faster. On the 4 processor box,
Lock-Free was a tiny bit faster. On the 16 processor box it wasn't even
close - lock free won by more than an an order of magnitude.
What this ended up telling me is that I need a "smart queue" and "smart
list" that can look at the number of processors and make the decision which
algorithm to use.
--
Chris Mullins
"Greg Young" <druckdruckREMOVEgoose@hotmail.com> wrote
> Don't use locking ....
>
> There is a great implementation of a lock free queue here
>
http://www.boyet.com/Articles/LockfreeQueue.html. He also has a library
> you can download which includes the implementation.
>
> Cheers,
>
> Greg Young
> MVP - C#
>
http://codebetter.com/blogs/gregyoung
>
> "Thana N." <ThanaN@discussions.microsoft.com> wrote in message
> news:2AB5349E-42CF-43C7-A6D2-9146450CA820@microsoft.com...
>> Dear Guys,
>>
>> I write program that sharing Queue between 2 threads which 1 thread add
>> data
>> to Queue. And another thread get data from Queue to process. My
>> situation
>> is if there are alot of data to add (like loop to add). The 2nd thread
>> which
>> try to get data from Queue cannot access or rarely to access that Queue
>> which
>> make the program has low performance.
>>
>> How can I do to improve this situation? I want 2nd thread can access as
>> fast as possible once Queue is not empty.
>>
>> Here is some snippet code:-
>>
>> Thread#1
>>
>> For i as Integer = 1 To 1000
>> SyncLock _queue.SyncRoot
>> _queue.Enqueue(i)
>> _newItemEvent.Set()
>> End SyncRoot
>> Next
>>
>>
>> Thread#2
>>
>> Dim item As Integer
>> While _queue.Count <= 0
>> Thread.SpinWait(0)
>> End While
>>
>> While _queue.Count > 0
>> SyncLock _queue.SyncRoot
>> item = DirectCast(_queue.Dequeue(), Integer)
>>
>> ....
>> End SyncLock
>> End While
>>
>>
>> Thanks,
>> Thana N.
>>
>
>