Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Multithreading done "right"

Multithreading done "right"

Scheduled Pinned Locked Moved The Weird and The Wonderful
performancequestion
24 Posts 14 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Member 7679313

    Call me a nice guy who generally gives people the benefit of the doubt, but this looks like code where someone INTENDED for some operations to occur on separate threads asynchronously, put some of the plumbing in, put a thread.join in for synchronous debugging, and never got back to it. You are correct in that the code would be more performant without creating the additional thread as they presently are, but the context of the usage is also important in determining your predecessor's intent. If GenerateTimeLineImage() is a void function that is basically a "fire and forget" service call, commenting out m_thread.Join() might increase application performance, and by quite a bit. I'll tell you that there is no hidden magic, but you haven't provided enough context for me to be as condemning as some other folks here.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #21

    Member 7679313 wrote:

    Call me a nice guy who generally gives people the benefit of the doubt, but this looks like code where someone INTENDED for some operations to occur on separate threads asynchronously, put some of the plumbing in, put a thread.join in for synchronous debugging, and never got back to it.

    Ok, I call you a nice guy :) He did write that he found this in serveral places in the code, wich makes some kind of accident less likely. I would just take a look at some other projects he worked on and if something like that also appears there, then there is little room left for doubt.

    At least artificial intelligence already is superior to natural stupidity

    1 Reply Last reply
    0
    • F Fedor Hajdu

      I recently started working for a new company and found quite a few situations like this:

      Thread m_thread = new Thread(new ThreadStart(GenerateTimeLineImage));
      m_thread.Start();
      m_thread.Join();

      I'm no expert on mulithreading but there are so many different (not just brainless copy-paste) of code like that, that it made me wondering is there some hidden magic behind that code that I'm not aware of. So, what's the difference between that and

      GenerateTimeLineImage();

      besides obvious performance loss due to creating a pointless thread?

      K Offline
      K Offline
      KP Lee
      wrote on last edited by
      #22

      If GenerateTimeLineImage is managing multiple threads, then the code makes sense. If not, then the coder read something, didn't understand it, but thought it was "cool", without understanding what the method was for.

      1 Reply Last reply
      0
      • F Fedor Hajdu

        He's not, I'm his replacement... :)

        S Offline
        S Offline
        spencepk
        wrote on last edited by
        #23

        That explains everything :)

        1 Reply Last reply
        0
        • F Fedor Hajdu

          I recently started working for a new company and found quite a few situations like this:

          Thread m_thread = new Thread(new ThreadStart(GenerateTimeLineImage));
          m_thread.Start();
          m_thread.Join();

          I'm no expert on mulithreading but there are so many different (not just brainless copy-paste) of code like that, that it made me wondering is there some hidden magic behind that code that I'm not aware of. So, what's the difference between that and

          GenerateTimeLineImage();

          besides obvious performance loss due to creating a pointless thread?

          F Offline
          F Offline
          Florin Jurcovici
          wrote on last edited by
          #24

          If there's version control in place, have a look - it might be that previous versions had some code between .Start() and .Join().

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups