I have created a function that does some processing in a thread so as not to block the window loop (otherwise Windows flags it as "not responding"). It is fairly straightforward code, since all I did was cut the in-line code out of the case, place it into a __stdcall function and reassigned some variables as passed parameters. I know the code is okay, because it works fine if I call the threadfunc explicitly, but whenever I call it through _beginthreadex it stops responding (the thread is launched fine and runs for a bit but crashes afterwards, using breakpoints throughout the code did not limit the scope of the error either). So what is causing the function to not respond when called in a threading context (i.e. what about it is not thread-safe)?
I've checked all parameters passed to the threadfunc from the caller (and its caller) and made sure that any local vars passed around are not sent off the stack before the thread can finish executing. The only other source of error I can guess would be a WinAPI call or C call from within the thread that is not threadsafe (though am I am positive I am using no un-thread-safe C calls).
To be specific, the parameter passed through the "void *pArgs" parameter of the thread is a pointer to a structure I defined consisting of 3 members, each holds a handle to window/control. I use these members (handles) with SendMessage() and GetDlgItem() from within the thread to send messages to controls. Are these winAPIs thread-safe? I know winAPI checks that some operations on handles can only be done if the calling process is owned by the Window's process (which I'm pretty sure is my case here right?) What else could potentially be causing this problem?
Thanks for any help.