DWORD WINAPI
GetFileNameThread (PVOID lpParameter)
{
PNM_INFO NmInfo=lpParameter;
IO_STATUS_BLOCK IoStatus;
NtQueryInformationFile (NmInfo - & gt; HFile, & amp; IoStatus, & amp; NmInfo - & gt; Info,
Sizeof (NM_INFO) - sizeof (HANDLE), FileNameInformation);
return 0;
}
EXTERN_C void GetFileName (HANDLE hFile, PCHAR TheName)
{
HANDLE hThread;
PNM_INFO Info=HeapAlloc (hHeap, 0, sizeof (NM_INFO));
The Info - & gt; HFile=hFile;
HThread=CreateThread (NULL, 0, GetFileNameThread, Info, 0, NULL);
If (MsgWaitForMultipleObjects (1, & amp; HThread,
FALSE, INFINITE, QS_ALLINPUT)==WAIT_OBJECT_0)//the problem here
{
The TerminateThread (hThread, 0);
}
The CloseHandle (hThread);
Memset (TheName, 0, MAX_PATH);
WideCharToMultiByte (CP_ACP, 0, Info - & gt; The Info. The FileName, Info - & gt; Info. FileNameLength & gt;> 1, TheName, MAX_PATH, NULL, NULL);
HeapFree (hHeap, 0, Info);
}
The process and thread creation, the first 100 threads are no problem, but then when the waitforsingleobject child thread collapses, the main thread deadlock, beg to solve!
CodePudding user response:
"Windows core programming"CodePudding user response:
What do you mean, this book have?CodePudding user response:
Thread 'Win32 threads (0 x9b4) have withdrawn, the return value is - 1073741510 (0 xc000013a),Thread 'Win32 threads (0 x2640) have withdrawn, the return value is - 1073741510 (0 xc000013a),
Thread 'Win32 threads (0 x2088) have withdrawn, the return value is - 1073741510 (0 xc000013a),
Program "[9648] cheumn. Exe: this machine" has quit, the return value is - 1073741510 (0 xc000013a),
After the deadlock is like this
CodePudding user response:
Every time is open to a problem with the 117th threadsCodePudding user response:
0 xc000013a failed to create a thread?CodePudding user response:
Ah, this is a deadlock or creating failed, why the main thread to exit if create failure? By adjusting and I found that seems to have been the cause of the induction of this phenomenon is the same file handleCodePudding user response:
This is stuck
CodePudding user response:
"The same file handle"The log file!
CodePudding user response:
The return value of a variable initialization, testing each step,
DWORD WINAPI GetFileNameThread (PVOID lpParameter)
{
PNM_INFO NmInfo=(PNM_INFO lpParameter);
If (NmInfo)
{
IO_STATUS_BLOCK IoStatus={0};
NtQueryInformationFile (NmInfo - & gt; HFile, & amp; IoStatus, & amp; NmInfo - & gt; Info,
Sizeof (NM_INFO) - sizeof (HANDLE), FileNameInformation);
}
return 0;
}
EXTERN_C void GetFileName (HANDLE hFile, PCHAR TheName)
{
If (TheName)
{
Memset (TheName, 0, MAX_PATH);
}
HANDLE hThread=NULL;
PNM_INFO Info=(PNM_INFO) HeapAlloc (hHeap HEAP_ZERO_MEMORY, sizeof (NM_INFO));
DWORD dwErr=0;
If (Info!=NULL)
{
The Info - & gt; HFile=hFile;
HThread=CreateThread (NULL, 0, GetFileNameThread, Info, 0, NULL);
If (hThread)
{
DWORD dwWait=WaitForSingleObject (hThread, INFINITE);
If (dwWait==WAIT_OBJECT_0)
{
WideCharToMultiByte (CP_ACP, 0, Info - & gt; The Info. The FileName, Info - & gt; Info. FileNameLength & gt;> 1,
TheName, MAX_PATH, NULL, NULL);
OutputDebugStringA (TheName);
OutputDebugStringA (" \ r \ n ");
}
The else
{
DwErr=GetLastError ();
TRACE (_T (" WaitForSingleObject failed % u \ n "), dwErr);
}
The CloseHandle (hThread);
}
The else
{
DwErr=GetLastError ();
TRACE (_T (" CreateThread failed % u \ n "), dwErr);
}
HeapFree (hHeap, 0, Info);
}
The else
{
DwErr=GetLastError ();
TRACE (_T (" HeapAlloc failed % u \ n "), dwErr);
}
}
CodePudding user response:
Specific what to do, I am a little white, the great god to solveCodePudding user response:
There is also a doubt is: the same handle, the handle work in named pipe, I create a thread is in order to get the pipe, the program's name piped goes like this:But in front of the named pipe:
This can be, but just the named pipe not line, can also lead to the thread exits, why is this?
CodePudding user response:
Using a thread pool,CodePudding user response:
Haven't solve ohoo...CodePudding user response:
A named pipe is blocked waiting state enumeration so your code to handle to a named pipe will die lock away, and thread not threads do not have what relation,GetFileInformationByHandleEx can't use? Want to write?