Using Interlocked to allow a single thread access to a resoure.(lysaghtn.weebly.com)

submitted by bigtoebigtoe(25) 3 years, 11 months ago

Using SyncLock (or lock in C#) to block all threads accessing a block of code can be overkill. SyncLock requires that all CPU instructions be cleared from the registers so that thread synchronization can be performed safely and it also requires a lot of management by the .NET threading libraries. In certain situation where multiple threads are running, you may require that just a single thread execute a piece of code at any one time. I've used this in situations where multiple threads are there for performance reasons but only 1 thread at a time should say clear down/refresh cache entries, but any of those threads could do the work.

1 comment |category: |Views: 18

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by gregbeechgregbeech(76) 3 years, 11 months ago 0

You might also want to check out Jeffrey Richter's SpinWaitLock which is a more complete implementation of the same concept (with the required things such as Begin/EndCriticalRegion calls): http://msdn.microsoft.com/en-us/magazine/cc163726.aspx

Reply

information Login or create an account to comment on this story