You certainly can do what you want and you thinking is very good, but you mixed up things with the opposites.
The pointer "this" is only passed the the instance (non-static) method, and not passed to the static method. Things are just the opposite. This is the exact essential difference between static and instance methods.
Now, the problem with C++ is:
_beginthread
and
_beginthreadex
expect a pointer to a static function (unlike .NET where you can use either instance of static method in the thread constructor). Of course you should use instance method! But how? You can pass this as an additional parameter using
_beginthreadex
. This work-around is well explained in this article:
http://www.computersciencelab.com/MultithreadingTut1.htm[
^].
Locate the code sample with the comment "arg list holding the "this" pointer". It shows how to pass "this" and use it int the thread function.
That said, it is very good to use a thread through a thread wrapper class implementing the thread method. In this case, you can exchange data between the wrapped thread and other threads at any time (not just at start), with proper synchronization, of course. I feel that you almost came to right solution, but mixed up thing by some reason. Not to worry.
Please also see how the code of the wrapper class could look and be used from my past answers:
How to pass ref parameter to the thread[
^],
change paramters of thread (producer) after it started[
^].
I apologize that the code in C# (where you can really use an instance method), not in C++, but the rest is very similar, at least the idea.
[EDIT]
I'm also asking my colleagues to contribute to answering this question. I would expect that such C++ thread wrapper class already exists in the form of ready-to-use base class or template class, which could be derived in a purely object-oriented manner with abstract or pseudo-abstract thread method to be overridden. I hope such thing exists in some of the C++ libraries which I don't remember or don't know. Let's see.
—SA