Link to home
Start Free TrialLog in
Avatar of thready
thready

asked on

CreateThread & WaitForSingleObject

Hi Experts,

I'm creating a thread like this:
DWORD dwThreadID;
m_hMyThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyThProc, (LPVOID*) this, 0, &dwThreadID);

Later on, I'm waiting on this thread to finish, with this:
WaitForSingleObject(m_hMyThread, INFINITE);

It seems to be deadlocked.  Is this because this just won't work?  Or is it because something else in my code somewhere is likely deadlocking?

Thanks!
Mike
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready
thready

ASKER

Thank you Sara, I did do something similar to this- nice answer!

I actually had a silly bug which prompted this question.  But I always get good stuff on here.... :)

Cheers,
Mike
thanks Mike.

i saw the following by rereading the question:

(LPVOID*) this

LPVOID already is void*.  so LPVOID* actually is void** (what doesn't make any difference to the call though).

you could omit the cast at all since the compiler always would allow an implicit cast to void* . the compiler even accepted the pointer to pointer as a valid argument for void* without warning.

Sara
Avatar of thready

ASKER

I just saw your last comment- double awesome.  Thanks!  :-)