399 Subj : Re: threading problem in dll??? Help needed badly. To : comp.programming.threads From : Paul Pluzhnikov Date : Thu Jul 07 2005 04:47 pm chuayongquan@hotmail.com writes: > UINT abc::abcfunction(LPVOID pParam) > { > > abc* pCM = (abc*)pParam; > > ::CoInitialize(NULL); > > while (1) { > TryEnterCriticalSection(CS); [1] What happens if the CS is already owned by another thread at point [1] above? The TryEnterCriticalSection() will fail, but you proceed as if it didn't. Subsequent calls to LeaveCriticalSection() will cause all manner of corruption. > // my thread code here > if (stopthread){ > LeaveCriticalSection(CS); > break; > } > LeaveCriticalSection(CS); > } > ::CoUninitialize(); > return 0; > } > > //end thread function Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. . 0