I've search the net and come across _beginthread,_beginthreadex and CreateMutex which can handle the function to be threaded.
My question is, how do use those function respectfully to be able to get the return value of the threaded function and pass a single argument which always changes?
>> and come across _beginthread, _beginthreadex and Create[Thread] which can handle the function to be threaded.
Prefer _beginthreadex over the other two - http://msdn.microsoft.com/en-us/library/kdzttdcb.aspx
>> how ... to get the return value of the threaded function
You can use GetExitCodeThread().
>> and pass a single argument
The fourth parameter to _beginthreadex() allows you to pass thread-specific parameters to your thread functions.
>> ... which always changes
If multiple threads are accessing the same data, and at least one thread is writing, the you'll need to synchronize access to that data - using a CRITICAL_SECTION for example.
How do I get the return value of foo not the exit code of foo;for instance,
my_return_datatype foo(my_argument_datatype) when being threaded?
In Windows, threads return a DWORD and GetExitCodeThread() is how you get that value.
If you need to "return" some other data type then you'll have to manage that yourself.
All threads allow you to pass an extra void* parameter that services as a parameter send to your thread function. You can use it to pass data to the thread and from the thread.