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. General Programming
  3. C / C++ / MFC
  4. Which would you use - a static or member function for your worker thread?

Which would you use - a static or member function for your worker thread?

Scheduled Pinned Locked Moved C / C++ / MFC
combusinesshelpquestionannouncement
3 Posts 2 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.
  • B Offline
    B Offline
    Ben Aldhouse
    wrote on last edited by
    #1

    I'm currently working on a rewrite of my most recent article Monitoring and Controlling a Recursing Function in a Worker Thread. I was as happy as someone could be when they've managed to get something that they've been very baffled by to actually do what they wanted it to do when I submitted the original article. Luckily for me, though, someone who is a better programmer than I kindly pointed out the short cuts in it which I was too ignorant to even know I'd made. So - sixteen months after posting the original article I am currently preparing an update which includes new code employing exclusion techniques which, I hope, satisfies thread safety requirements thereby making the article more useful to people who want to base more complex threaded software on it. Beyond the thread safety issue, I also looking in to the issue of making the thread function a global (non static) function. This was suggested as a possibility to me. I am not sure why this might be a benefit. The process of re-implementing the function is helping me to attend to the threadsafe issues, though. I would be very glad to hear of any ideas you have of the benefits of moving the function to a global scope - or possibly keeping it as a member function. Thanks, Ben.

    C 1 Reply Last reply
    0
    • B Ben Aldhouse

      I'm currently working on a rewrite of my most recent article Monitoring and Controlling a Recursing Function in a Worker Thread. I was as happy as someone could be when they've managed to get something that they've been very baffled by to actually do what they wanted it to do when I submitted the original article. Luckily for me, though, someone who is a better programmer than I kindly pointed out the short cuts in it which I was too ignorant to even know I'd made. So - sixteen months after posting the original article I am currently preparing an update which includes new code employing exclusion techniques which, I hope, satisfies thread safety requirements thereby making the article more useful to people who want to base more complex threaded software on it. Beyond the thread safety issue, I also looking in to the issue of making the thread function a global (non static) function. This was suggested as a possibility to me. I am not sure why this might be a benefit. The process of re-implementing the function is helping me to attend to the threadsafe issues, though. I would be very glad to hear of any ideas you have of the benefits of moving the function to a global scope - or possibly keeping it as a member function. Thanks, Ben.

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      IMO, it's just a matter of style. if your thread func needs to access something that's defined inside the class (typedefs, enums, child classes, etc.) then it makes sense to use a static member function. but if the thread func doesn't need anything like that, i'd use a global static.

      image processing toolkits | batch image processing

      B 1 Reply Last reply
      0
      • C Chris Losinger

        IMO, it's just a matter of style. if your thread func needs to access something that's defined inside the class (typedefs, enums, child classes, etc.) then it makes sense to use a static member function. but if the thread func doesn't need anything like that, i'd use a global static.

        image processing toolkits | batch image processing

        B Offline
        B Offline
        Ben Aldhouse
        wrote on last edited by
        #3

        Thanks! That's the impression I've been getting.

        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