Why ++ operator is not thread safe(blog.decarufel.net)

submitted by decarufedecarufe(959) 3 years ago

Here is a quick hint on how to make your software thread safe.

2 comments |category: |Views: 515

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 JonnyRocksJonnyRocks(0) 2 years, 11 months ago 0

This article is not well written out.
Are you saying your variable is static? then i guess you are right?
but if threads are creating instances of these classes then each thread has its own copy.

Obviously the poster ran into an issue and made his scenario fit all.

Thats like me saying don't walk outside. Everytime you walk outside you get shot.

Then you research and come to fin out I was walking in a heavily contested area of Iraq shoouting obscenities.

Reply

posted by zoidbeckzoidbeck(0) 2 years, 7 months ago 0

I think you comment seems to have the same problem. This IS of course about shared instances, static or not. If each thread has its own copy you won't have to bother about thread safety at all. But imo getting this informations about threadsafety of such a fundamental and basic operation like ++ helps you gettin aware about hard to track threadding related bugs.
So maybe this trival information is in fact missing but though i find this article quite helpfull.

Reply

information Login or create an account to comment on this story