Gyannea
December 23rd, 2002, 03:02 PM
Hello World!
I had hoped to create a radio scanner object which when created would create its own window, callback function, and thread in which to execute. A main control would then oversee several scanners each controlling a receiver.
Alas, there are difficulties doing that since callback functions and threads are static function and they cannot be made member of a class without being declared as 'static' which defeats the purpose of encapsulating them.
Now the question was what happens if several threads are created and each accesses the same function; the only difference is that a a different pointer is passed to the thread which then is passed to the function.
Does the thread encapsulate the function, in other words, is there a unique copy of that function made in memory for each thread?
It seems to be the case, but I am not sure. I tried a simple example where three threads are created each being passed a structure pointer containing the handles to a window, virtual window, and it device handle. The function called contained an infinite loop that does nothing but draw different colored ellipses that fill the window and continuously recycle.
If the function was "encapsulated" then I should see ellipses generated in each of the windows. And that I did. However, not all of the virtual windows seemed to get filled. Sometimes only one did, sometimes two, and sometimes all three.
Does anybody know how Windows threads really handle functions?
Thanks for any help and if you even made it through this long thread!
I had hoped to create a radio scanner object which when created would create its own window, callback function, and thread in which to execute. A main control would then oversee several scanners each controlling a receiver.
Alas, there are difficulties doing that since callback functions and threads are static function and they cannot be made member of a class without being declared as 'static' which defeats the purpose of encapsulating them.
Now the question was what happens if several threads are created and each accesses the same function; the only difference is that a a different pointer is passed to the thread which then is passed to the function.
Does the thread encapsulate the function, in other words, is there a unique copy of that function made in memory for each thread?
It seems to be the case, but I am not sure. I tried a simple example where three threads are created each being passed a structure pointer containing the handles to a window, virtual window, and it device handle. The function called contained an infinite loop that does nothing but draw different colored ellipses that fill the window and continuously recycle.
If the function was "encapsulated" then I should see ellipses generated in each of the windows. And that I did. However, not all of the virtual windows seemed to get filled. Sometimes only one did, sometimes two, and sometimes all three.
Does anybody know how Windows threads really handle functions?
Thanks for any help and if you even made it through this long thread!