Issues with Multithreaded Programming: Part 1

By , June 21, 2011

Multithreaded (Parallel) programming is difficult for many reasons. Developer always has to put extra care to protect the program from issues like race condition, deadlocks, livelocks, priority inversions, two-step dances, and lock convoys. My personal experience says these all issues are tough to identify and then resolve.

It is always better to have understanding on these issues before writing multithreaded application. In this article I have covered the quick overview of following issues associated with multithreaded programming:

Race Condition

A race condition occurs when two or more threads are able to access shared data and they try to change it at the same time. Because the thread scheduling algorithm can swap between threads at any point, we cannot know the order at which the threads will attempt to access the shared data. Therefore, the result of the change in data is dependent on the thread scheduling algorithm, i.e. both threads are ‘racing’ to access/change the data.

Often problems occur when one thread does a “check-then-act” (e.g. “check” if the value is X, and then “act” to do something that depends on the value being X) and another thread does something to the value in between the “check” and the “act”.

In order to prevent race conditions occurring, typically put a lock around the shared data to ensure that only one thread can access the data at a time. (Read more about how to put lock and different techniques to synchronize the threads – C#: Thread Synchronization)



A deadlock occurs when two or more processes/threads are unable to proceed because each is waiting or one of the others to do something.

A common example is a program communicating to a server, which may find itself waiting for output from the server before sending anything more to it, while the server is similarly waiting for more input from the controlling program before outputting anything.

Another common example in which each process is trying to send stuff to the other but all buffers are full because nobody is reading anything.

Another example, common in database programming, is two processes that are sharing some resource (e.g. read access to a table) but then both decide to wait for exclusive (e.g. write) access.

The real world example will be interactions between humans, as when two people meet in a narrow corridor, and each tries to be polite by moving aside to let the other pass, but they end up swaying from side to side without making any progress because they always move the same way at the same time.


Other issues of multithreaded programming like “LiveLock“, “Priority Inversion“, “Two-Step Dances” and “Lock Convoys” are covered in “Issues with Multithreaded Programming : Part 2” and  “Issues with Multithreaded Programming – Part 3”.

72 Responses to “Issues with Multithreaded Programming: Part 1”

  1. Pinki says:

    I agree – one should know what will be issue with multithreding application before coding.

    The rece condition and deadlock are very common issues people face…

    nicely explained… thanks

  2. Pankaj says:

    How to prevent from deadlock?

    Could you please add one example?

  3. What’s up mates, its wonderful piece of writing on the topic of tutoringand fully
    explained, keep it up all the time.

  4. Simply dssire to say your article is as astonishing.
    The clarity in your post is simply great and i could assume yyou are an expert on this subject.
    Fine with youyr permission allow me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please carry on the gratifying work.

  5. Impressive business video is capable of getting more likes and comments.
    Effectively, naturally I will have answers to any or all of one’s
    queries. Provides you with the most convenient task management
    along with the easiest control capability.

  6. Dorthy says:

    The software has a Outlook-similar interface and previews messages
    in 3-panes. There are several types of college papers that college professors prefer to give to their students.

    He might even start wondering if you’ve got another guy
    in mind (or may have started dating someone else already).

  7. Carlos says:


    tnx for info!

  8. billy says:


    tnx for info.

  9. Currently it seems like Drupal is the preferred blogging platform available right
    now. (from what I’ve read) Is that what you are using on your blog?

  10. This post is invaluable. When can I find out more?

  11. Arnette says:

    It’s amazing to pay a visit this web page and reading the views off alll
    mates on the topic of this post, while I am also zealous off getting know-how.

  12. Have you ever thought about adding a little bit more
    than just your articles? I mean, what you say is valuable and all.

    But think about if you added some great photos or video clips to
    give your posts more, “pop”! Your content is excellent but with pics and clips,
    this site could certainly be one of the best in its field.
    Great blog!

  13. I enjoy, cause I found just what I used to be taking a look for.
    You have ended my four day lengthy hunt! God Bless you man. Have a great day.


  14. Hi there, I log on to your blogs like every week. Your humoristic style is awesome,
    keep doing what you’re doing!

  15. Howdy, i read your blog from time to time and i own a similar one andd
    i was just curious if you gett a llot of spam
    feedback? If so how do you stop it, any plugin or anything
    you can suggest? I get so much lately it’s driving me madd so any help is very much

  16. Hola , ​​Me gusta leer través de su artículo
    . I gusta para escribir un pequeño comentario para apoyarle.

  17. Appreciation to my father who shared with me on the topic of this webpage,
    this website is really awesome.

  18. Hi there fantastic website! Does running a blog like this
    require a lot of work? I have no understanding of computer programming however I had been hoping to start my
    own blog soon. Anyhow, if you have any suggestions or techniques
    for new blog owners please share. I understand this is off
    topic nevertheless I simply wanted to ask. Many thanks!

  19. Excellent, what a web site it is! This web site provides valuable information to us, keep it up.

  20. Does your site hae a contact page? I’m having trouble locating it but,
    I’d like to send you an e-mail. I’ve got some
    ideas for your blog you might be interessted in hearing. Either way, great website and I look forward to seeing it grow over time.

  21. Woah! I’m really enjoying the template/theme of this blog.
    It’s simple, yet effective. A lot of times it’s difficult
    to get that “perfect balance” between usability and appearance.
    I must say you have done a great job with this.

    Also, the blog loads very quick for me on Chrome. Outstanding Blog!

  22. picture fram says:

    Thorn of Girl

    Superb info may be discovered on this website website.

  23. I just couldn’t depart your website before suggesting that I really enjoyed the standard info an individual provide for your visitors?

    Is gonna be again incessantly to check up on new posts

  24. I was pretty pleased to uncover this website.

    I need to to thank you for your time due to this wonderful read!!
    I definitely enjoyed every bit of it and i also have you
    saved to fav to look at new stuff on your blog.

  25. Souls in the Waves

    Superior Early morning, I just stopped in to go to your site and assumed I’d say I appreciated myself.

  26. Whispering Misty

    So sorry you’ll pass up the workshop!

  27. The Absent Game

    Involving me and my husband we’ve owned much more MP3 players over time than I can count, which includes Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few many years I’ve settled down to one line of gamers.

  28. I blog frequently and I seriously thank you for your information. This
    great article has really peaked my interest. I will take a note of your site and keep checking for new information about once per week.
    I opted in for your RSS feed too.

  29. If you are going for most excellent contents like me,
    only pay a quick visit this web site all the time for the reason that it presents quality contents, thanks

  30. You actually make it seem so easy together with your presentation however
    I in finding this matter to be really something which I beliece I might nevber understand.
    It kind of feels too complex and extremely large foor
    me. I’m having a look forward in your subsequent put up, I will try to get the
    cling of it!

  31. Great post. I was checking continuously this blog and I am impressed!

    Extremely helpful info specially the last part :) I care for such information a
    lot. I was seeking this particular information for a very long time.
    Thank you and good luck.

  32. My Homepage says:

    … [Trackback]

    […] Informations on that Topic: […]

  33. Thanks for some other great article. Where else may anyone get that kind of info in such an ideal approach of writing?

    I have a presentation subsequent week, and I’m at the
    look for such info.

  34. Just desire to say your article is as surprising.
    The clearness in your post is simply cool and i could assume you are an expert on this
    subject. Well with your permission allow me to grab your feed to keep updated with forthcoming post.
    Thanks a million and please keep up the gratifying work.

  35. Julienne says:

    Its not my first time to payy a quick visit this site,
    i am browsing this website dailly and take fastidious facts from here everyday.

  36. Poi c’è la possibilità di completare gli obiettivi proposti
    dal gioco, che in premio offrono proprio diamanti.

  37. Nevertheless we at Android Veterans have created a cheat for Shadow Battle 2, which allows you to have an infinite amount of gems,
    cash and vitality. In the event you beloved this text and you wish
    to get hold of extra particulars pertaining to insane hackz – -struggle-2-cash-hack-wonderful-suggestions-…

    kindly pay a visit to our web-page.

  38. In spite of everything we psychics get your self quite a few calls
    concerning this – does he have shadow combat
    2 hack – , one different woman. Different potential causes in your extinction of codes may embody the arrival of achievements, DLC, trophies and
    in addition the rising availability of on-line multiplayer.

  39. In such a method, you might be being protected from the risk of
    them discovering it out – and even if they do find about it, you can simply
    take away the hack and present them how you will have advanced because of utilizing
    it before. The hack works effectively on Android and iOS
    units so you have nothing to fret about compatibility.

  40. (Note that a human verification may be required in some international
    locations attributable to spam-battle).

  41. Hi there! Someone in my Myspace group shared this
    website with us so I came to take a look. I’m definitely
    loving the information. I’m bookmarking aand will be
    tweeting this to my followers! Wonderful blog aand brilliant design and style.

  42. You’ll most likely be thrilled to master that the first elements stay accessible inside present versions.

    Five’s are price 5 issues each, and 10’s and Kings are worth 10 components each.

  43. 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 e-mails with the same comment. Is there any way you can remove me from
    that service? Appreciate it!

  44. Brandon says:



  45. fredrick says:


    ñïñ çà èíôó.

  46. At this time it looks like Expression Engine is the preferred blogging
    platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  47. Good answer back in return of this difficulty with genuine arguments and explaining everything about that.

  48. Hello, i think that i saw you visited my weblog thus i came to go back
    the choose?.I’m attempting to in finding issues to improve my website!I
    assume its adequate to make use of a few of your ideas!!

  49. Amazing! This blog looks just like my old one! It’s on a completely
    different topic but it has pretty much the same layout and design. Wonderful choice of colors!

  50. I read this paragraph fully about the difference of most
    recent and preceding technologies, it’s amazing article.

  51. enrique says:



  52. Truly no matter if someone doesn’t understand then its up to
    other visitors that they will assist, so here it occurs.

  53. You actually make it seem really easy along with
    your presentation but I find this matter to be really one thing that I feel
    I would never understand. It seems too complex and extremely huge for me.
    I’m taking a look forward to your subsequent submit, I’ll attempt to get the hold
    of it!

  54. Great blog right here! Additionally your web site quite a bit up very fast!
    What host are you the usage of? Can I am getting your associate link in your host?
    I want my web site loaded up as quickly as yours lol

  55. I think that what you posted was actually very logical. However, what about this?

    suppose you added a little information? I mean, I don’t want
    to tell you how to run your blog, however suppose you added
    a headline that makes people want more? I mean Ashish Khandelwal

  56. However we at Android Veterans have created a cheat for Shadow Struggle 2,
    which lets you have an infinite amount of gems, cash
    and vitality. When you beloved this text and you want to acquire extra
    details pertaining to insane hackz – -combat-2-cash-hack-amazing-tips-…
    kindly pay a go to to our internet-page.

  57. Hi there! I realize this is sort of off-topic however I
    needed to ask. Does building a well-established website such as yours require a large amount of
    work? I’m brand new to running a blog but I do write in my diary on a
    daily basis. I’d like to start a blog so I will be able to share my
    personal experience and thoughts online. Please let me know if you have
    any kind of ideas or tips for brand new aspiring bloggers.
    Appreciate it!

  58. This sport also our competition. Anyone can enjoy the expertise
    before. Because the cellular video games to puzzles, vocabulary video games, one should play
    it over lone sort out massive destruction.

  59. Shadow Fight 2 Hack Software 2014 is the most effective hack i ever discovered online.
    You may download this free Shadow Struggle 2 Hack Device as by simply clicking
    the obtain button bellow.

  60. It’s impressive that you are getting thoughts from tis article aas well aas from our discussion made at this time.

  61. Vital: Shadow Battle 2 Gems Hack will change the quantity of your
    gems in game. The identical applied with cash.
    Use the Unlimited Vitality” to by no means
    run out of energy while playing, this function will let you finish acts simply,
    as you needn’t to wait any more for energy to refill.

  62. To cope with it’s quite attainable, however cross all the levels, in this case it
    will be extremely tough. They counsel the cheat game ideas obtain may be
    avid fans of the style who are willing to bash enemies.

  63. This paragraph offers clear idea designed for the new users of blogging, that actually
    how to do running a blog.

  64. There are three most important things which might
    be a should within the Kill Shot: Gold, Bucks,
    and Power, with out sufficient of those you wont be capable of upgrade your weapons, pace up your
    progress, or go on that next mission, all the things will seem impossible.
    There are occasions in the app that you will have the chance to obtain Free Gold, Bucks, and Power,
    however soon you will notice this doesnt come enough.
    This leads to most customers having to shell out there money or use there itunes reward cards to get the required objects they need.

  65. Terrific post however I was wanting to know if you could write a litte more on tis topic?
    I’d be very grateful if you could elazborate a little
    bitt further. Appreciate it!

  66. It’s actually a great and helpful piece of information.
    I’m satisfied that you simply shared this useful info with us.
    Please keep us up to date like this. Thanks for sharing.

  67. Hi, I desire to subscribe for this blog to obtain most up-to-date
    updates, so where can i do it please assist.

Leave a Reply