This is a mirror of official site: http://jasper-net.blogspot.com/

Lock-free algorithms: The try/commit/(try again) pattern

| Wednesday, April 13, 2011
The singleton constructor pattern and the Interlocked­Multiply example we saw some time ago are really special cases of the more general pattern which I'll call try/commit/(try again). I don't know if this pattern has a real name, but that's what I'm calling it for today.

The general form of this pattern goes like this:

for (;;) {
 // capture the initial value of a shared variable we want to update
 originalValue = sharedVariable;

 ... capture other values we need to perform the operation ...
 ... these values must be indepedent of sharedVariable ...

 newValue = ... calculate the desired new result
                based on originalValue and other captured values ...

 // Xxx can be Acquire, Release, or null
 if (InterlockedCompareExchangeXxx(
            &sharedVariable,
            newValue, oldValue) == oldValue) {
  break; // update was successful
 }

 ... clean up newValue ...

} // loop back and try again

We calculate the desired new value based on the initial value, combining it with other values that vary depending on the operation you want to perform, and then use an Interlocked­Compare­Exchange to update the shared value, provided the variable hasn't changed from its initial value. If the value did change, then that means another thread raced against us and updated the value before we could; in that case, we go back and try it again. Maybe the next time through we won't collide against somebody.

Posted via email from Jasper-net

38 comments:

Anonymous said...

Yesterday, while I was at work, my cousin stole my iPad and tested to see
if it can survive a twenty five foot drop, just so she can be a youtube sensation.

My iPad is now destroyed and she has 83 views. I know this is entirely off topic but I had
to share it with someone!

my webpage - virginia auto insurance quotes

Anonymous said...

Howdy! Someone in my Myspace group shared this website with us so I came to give it a look.

I'm definitely enjoying the information. I'm book-marking and will
be tweeting this to my followers! Great blog and superb design.


Have a look at my page related webpage

Anonymous said...

Right now it appears like Wordpress is the top blogging platform available
right now. (from what I've read) Is that what you're using on your
blog?

Look at my blog Read the Full Post

Anonymous said...

Hmm is anyone else having problems with the images on this blog loading?
I'm trying to figure out if its a problem on my end or if it's the blog.
Any feed-back would be greatly appreciated.


My web site just click the next post

Anonymous said...

Hey there! I'm at work surfing around your blog from my new apple iphone! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the fantastic work!

Feel free to surf to my website ... Read the Full Article

Anonymous said...

We absolutely love your blog and find almost all of your post's to be just what I'm looking for.
Would you offer guest writers to write content in your case?
I wouldn't mind creating a post or elaborating on most of the subjects you write concerning here. Again, awesome site!

Feel free to surf to my blog post :: similar webpage

Anonymous said...

Heya! It looks as though we both have a interest for the same thing.
Your blog, "Blogger: Jasper22.NET" and mine are very similar.
Have you ever thought about authoring a guest article for a
related blog? It will certainly help gain exposure to your
blog (my site recieves a lot of visitors). If you happen to be interested,
e-mail me at: harrisongraves@gmail.com. Thank you so much

My blog post ... This Web-site

Anonymous said...

I have fun with, result in I discovered just what I used to be taking a look for.

You have ended my four day long hunt! God Bless
you man. Have a great day. Bye

Review my web page link building service

Anonymous said...

Browsing reddit.com I noticed your website book-marked as:
Blogger: Jasper22.NET. I am assuming you book-marked it yourself and wanted to ask if social book-marking gets
you a bunch of targeted traffic? I've been thinking about doing some bookmarking for a few of my websites but wasn't sure if it
would produce any positive results. Thank you.

My blog post ... Full Write-up

Anonymous said...

Surfing around stumbleupon.com I noticed your website bookmarked as:
Blogger: Jasper22.NET. I am assuming you book marked it yourself and wanted to ask if social book-marking gets you
a large amount of traffic? I've been looking at doing some bookmarking for a few of my sites but wasn't certain if it would yield any
positive results. Appreciate it.

Here is my webpage - www.pgillis.ch

Anonymous said...

Awesome blog! Do you have any tips and hints for aspiring writers?

I'm hoping to start my own site soon but I'm a
little lost on everything. Would you suggest starting with a free platform like Wordpress or go for a
paid option? There are so many options out there
that I'm totally overwhelmed .. Any ideas? Cheers!

My blog: Read the Full Report

Anonymous said...

Hi! Do you know if they make any plugins to safeguard against
hackers? I'm kinda paranoid about losing everything I've worked hard on.
Any recommendations?

My web blog: click the next page

Anonymous said...

My coder is trying to convince me to move to .net from PHP.

I have always disliked the idea because of the expenses.

But he's tryiong none the less. I've been using Movable-type on numerous websites for about a
year and am anxious about switching to another platform.
I have heard great things about blogengine.net.
Is there a way I can import all my wordpress content
into it? Any kind of help would be greatly appreciated!


My web page ... Click On this website

Anonymous said...

Please let me know if you're looking for a article author for your site. You have some really great articles and I think I would be a good asset. If you ever want to take some of the load off, I'd really like to write
some content for your blog in exchange for a link back to mine.
Please blast me an email if interested. Regards!


my site - Read More At this website

Anonymous said...

Surfing around reddit.com I noticed your website book-marked as: Blogger:
Jasper22.NET. Now i'm assuming you book-marked it yourself and wanted to ask if social book-marking gets you a ton of site visitors? I've been contemplating doing some social bookmarking for
a few of my sites but wasn't sure if it would yield any positive results. Appreciate it.

my blog; just click the following webpage

Anonymous said...

Would you mind if I quote a small number of your blog posts as long as I provide credit and sources returning to your site:
http://www.blogger.com/comment.g?blogID=5356530&postID=7246400863742241321.

I am going to aslo ensure to give you the appropriate anchortext hyperlink using your website title: Blogger: Jasper22.
NET. Please be sure to let me know if this is ok with you.

Thanks

Stop by my web site auto insurance colorado

Anonymous said...

Whoa! This blog looks exactly like my old one! It's on a totally different subject but it has pretty much the same page layout and design. Wonderful choice of colors!

Look at my site: Learn More

Anonymous said...

Hey I know this is off topic but I was wondering if you knew of any
widgets I could add to my blog that automatically tweet my
newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

Look into my blog cheapest auto insurance in california ()

Anonymous said...

Hiya. I was thinking about adding a backlink back to your blog since both of our web sites are based around
the same subject. Would you prefer I link to you
using your site address: http://www.blogger.com/comment.g?blogID=5356530&postID=7246400863742241321 or blog title: Blogger: Jasper22.
NET. Please make sure to let me know at your earliest convenience.
Kudos

Here is my website :: just click the up coming internet site

Anonymous said...

When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each
time a comment is added I get three emails with the same comment.
Is there any way you can remove me from that service?

Thank you!

My webpage; check it out

Anonymous said...

Hey! My name is Philip and I really just wanted to say your blogging site is awesome!

It's funny simply because I use to have a blog site that almost had an identical web address: http://www.blogger.com/comment.g?blogID=5356530&postID=7246400863742241321 mine was only a few characters different. Anyhow, I'm a big fan of your website
and if you ever want a guest post please make sure to
email me at: philipgriffin@gmail.com. I absolutely adore writing!


My page: visit this website ()

Anonymous said...

Admiring the dedication you put into your site and in
depth information you present. It's nice to come across a blog every once in a while that isn't the same
old rehashed information. Wonderful read! I've bookmarked your site and I'm adding your
RSS feeds to my Google account.

Feel free to surf to my site :: Click That Link - -

Anonymous said...

I was curious if you ever considered changing the structure of your
blog? Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content
so people could connect with it better. Youve got an awful
lot of text for only having one or 2 images. Maybe you could space it out better?


My page ... Suggested Website ()

Anonymous said...

Today, I went to the beach front with my kids.
I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell
to her ear and screamed. There was a hermit crab inside and it pinched
her ear. She never wants to go back! LoL I know this
is entirely off topic but I had to tell someone!

Visit my weblog ... website link

Anonymous said...

Howdy! This post couldn't be written any better! Reading this post reminds me of my old room mate! He always kept chatting about this. I will forward this article to him. Pretty sure he will have a good read. Many thanks for sharing!

Here is my web page: link building company - -

Anonymous said...

Would you mind if I quote a couple of your articles as long as
I provide credit and sources returning to your weblog: http://www.
blogger.com/comment.g?blogID=5356530&postID=7246400863742241321.
I'll aslo make certain to give you the appropriate anchor text hyperlink using your webpage title: Blogger: Jasper22.NET. Please be sure to let me know if this is okay with you. Thanks alot :)

Look into my homepage visit this page ()

Anonymous said...

It's a shame you don't have a donate button!
I'd certainly donate to this outstanding blog! I guess for now i'll settle for bookmarking and adding your RSS feed to my Google account.
I look forward to fresh updates and will share this blog with
my Facebook group. Talk soon!

my homepage :: check out the post right here ()

Anonymous said...

Please let me know if you're looking for a author for your weblog. You have some really good articles and I feel I would be a good asset. If you ever want to take some of the load off, I'd
love to write some articles for your blog in exchange for a link back to mine.
Please shoot me an e-mail if interested. Kudos!


Also visit my blog post: visit the up coming article

Anonymous said...

Heya administrator, I just wanted to give you a quick heads up
that your current Website link: http://www.

blogger.com/comment.g?blogID=5356530&postID=7246400863742241321 is being flagged as a potentially malicious blog in my browser opera.
I'd highly recommend having somebody look into it. You could very well lose a lot of guests due to this kind of problem. Best of Luck.

My homepage linked site ()

Anonymous said...

Hmm it appears like your blog ate my first comment (it was extremely long) so I guess
I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog.

I as well am an aspiring blog blogger but I'm still new to everything. Do you have any recommendations for first-time blog writers? I'd certainly appreciate it.


my web page; Full Piece of writing

Anonymous said...

Great blog you have here but I was wondering if you knew of any
user discussion forums that cover the same topics talked about
here? I'd really like to be a part of group where I can get advice from other knowledgeable people that share the same interest. If you have any suggestions, please let me know. Appreciate it!

Look into my blog post ... More methods

Anonymous said...

Hey there. I was considering adding a backlink back to your website since
both of our web sites are centered around the same subject.

Would you prefer I link to you using your site address:
http://www.blogger.com/comment.g?blogID=5356530&postID=7246400863742241321 or web site title: Blogger: Jasper22.
NET. Please let me know at your earliest convenience.
Many thanks

My website - Read Full Report

Anonymous said...

I am wondering which blogging and site-building platform
you might be running? I'm new to operating a blog and have been thinking about using the Hubpages platform. Do you consider this is a good foundation to start with? I would be very grateful if I could ask you some questions through e-mail so I can learn a bit more prior to getting started. When you have some free time, please get in touch with me at: svenspillman@gawab.com. Thank you

My web blog ... one way link building

Anonymous said...

We stumbled over here coming from a different web address and thought I
may as well check things out. I like what I see so
now i'm following you. Look forward to checking out your web page for a second time.

Here is my blog :: high pr backlinks list

Anonymous said...

I'm not sure exactly why but this weblog is loading incredibly slow for me. Is anyone else having this issue or is it a issue on my end? I'll check back later on and
see if the problem still exists.

Have a look at my blog links building service

Anonymous said...

Good day! I could have sworn I've been to this site before but after browsing through some of the post I realized it's
new to me. Nonetheless, I'm definitely glad I found it and I'll be bookmarking and checking
back frequently!

Check out my web blog ... link building firm

Anonymous said...

Good day! My spouse and I often write guest articles or blog posts for other blog owners to
help increase exposure to our work, as well as provide good
content to site owners. It really is a win win situation! If you are interested feel
free to e-mail me at: dorie_reeder@snail-mail.net so we may discuss further.
Thanks alot :)!

My blog :: search engine optimization seo serv.. ()

Anonymous said...

Awesome blog! Do you have any tips and hints for aspiring writers?
I'm planning to start my own site soon but I'm a little lost on everything.
Would you suggest starting with a free platform like Wordpress or go for a
paid option? There are so many options out there that I'm totally confused .. Any ideas? Thanks!

Also visit my web page; link building consultant