Which would you use - a static or member function for your worker thread?
-
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.
-
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.
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.
-
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.
Thanks! That's the impression I've been getting.