Click here to Skip to main content
15,905,420 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMultithreaded QuickSort Pin
Robert Buldoc4-Dec-03 16:29
Robert Buldoc4-Dec-03 16:29 
GeneralRe: Multithreaded QuickSort Pin
Xiangyang Liu 刘向阳8-Dec-03 1:13
Xiangyang Liu 刘向阳8-Dec-03 1:13 
QuestionThe Trouble with List Controls(CListCtrl)?? Pin
MissingLinkError4-Dec-03 16:23
MissingLinkError4-Dec-03 16:23 
AnswerRe: The Trouble with List Controls(CListCtrl)?? Pin
Abin4-Dec-03 20:18
Abin4-Dec-03 20:18 
GeneralRe: The Trouble with List Controls(CListCtrl)?? Pin
MissingLinkError5-Dec-03 9:32
MissingLinkError5-Dec-03 9:32 
Generalcontinuous voice problem Pin
yingkou4-Dec-03 15:46
yingkou4-Dec-03 15:46 
GeneralOpenGL problem on XP, wglMakeCurrent changes tooltips behavior for windows desktop Pin
Yawar Maajed4-Dec-03 14:20
Yawar Maajed4-Dec-03 14:20 
GeneralWaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva4-Dec-03 10:50
Kuniva4-Dec-03 10:50 
I have a function in my tcp server that starts a thread to try and stop the server, i'm using a thread because when the server stops, things have to be removed from a list of clients, and so it cant block the message queu or i cant use SendMessage(). The problem is that when i test, by connecting via telnet, and stop the server while the client is connected, WaitForMultipleObjects() usually returns WAIT_FAILED with error code 6 (Invalid handle). Only the first time i stop the server it sometimes works ok. But after that its always WAIT_FAILED. HEre's the code to the stopper thread:

DWORD WINAPI StopServerThread(void* prms)
{
	HWND hWnd = (HWND)prms;
	HL thread;
	HLI hli;

	int result=0;

	// Close the listener
	shutdown(sListener,SD_BOTH);
	closesocket(sListener);


	if(client.size()>0)
	{
		DWORD err;

		for(cli=client.begin();cli!=client.end();++cli)
		{
			thread.push_back((HANDLE)(*cli)->ThreadHandle);
		}

		if(!WSASetEvent(hSuicideEvent))
			MessageBox(hWnd,"WSASetEvent() failed","Error",MB_ICONERROR);
	
		result = WaitForMultipleObjects( thread.size(), thread.begin(), TRUE, 5000 );
		switch ( result )
		{
		case WAIT_TIMEOUT:
			ConsoleOutput("Not all threads died in time");
			break;
		case WAIT_FAILED:
			err = GetLastError();
			ConsoleOutput("WaitForMultipleObjects(): WAIT_FAILED (%i)", (int)err);
			break;
		default:
			ConsoleOutput("All client threads terminated successfully");
			break;
		}

		for ( hli = thread.begin(); hli != thread.end(); ++ hli )
			CloseHandle( *hli );

		client.clear();
		thread.clear();
	
	}

	DeleteCriticalSection(&lpCritSection);

	WSACloseEvent(hSuicideEvent);

	bIsRunning = FALSE;

	// Update the menu
	HMENU mainmenu = GetMenu(hWnd);
	EnableMenuItem(mainmenu,IDM_START,MF_ENABLED);
	EnableMenuItem(mainmenu,IDM_STOP,MF_GRAYED);

	ExitThread(0);

	return 0;
}


client is a list of client information, also containing the thread handles of each client thread. Weird thing is that the client threads DO exit and all, everything works fine except that WaitForMultipleObjects starts to return WAIT_FAILED. Anyone have any idea why?
Thanks

Kuniva
--------------------------------------------
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kelly Herald4-Dec-03 17:52
Kelly Herald4-Dec-03 17:52 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva5-Dec-03 0:19
Kuniva5-Dec-03 0:19 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva5-Dec-03 0:30
Kuniva5-Dec-03 0:30 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Mike Dimmick5-Dec-03 0:02
Mike Dimmick5-Dec-03 0:02 
GeneralRe: WaitForMultipleObjects always returns WAIT_FAILED Pin
Kuniva5-Dec-03 0:18
Kuniva5-Dec-03 0:18 
GeneralButton in windows forms..c++ Pin
mitil203904823044-Dec-03 10:36
mitil203904823044-Dec-03 10:36 
GeneralSwitching Views in SDI Pin
swerajan4-Dec-03 9:52
swerajan4-Dec-03 9:52 
GeneralRe: Switching Views in SDI Pin
Peter Molnar4-Dec-03 13:38
Peter Molnar4-Dec-03 13:38 
GeneralProblem with lpdirect3ddevice9 Pin
Simon Booth4-Dec-03 9:26
Simon Booth4-Dec-03 9:26 
GeneralRe: Problem with lpdirect3ddevice9 Pin
ZoogieZork4-Dec-03 18:17
ZoogieZork4-Dec-03 18:17 
GeneralPostMessage() problems Pin
Sid_smily4-Dec-03 9:18
Sid_smily4-Dec-03 9:18 
GeneralRe: PostMessage() problems Pin
David Crow4-Dec-03 9:24
David Crow4-Dec-03 9:24 
GeneralThe right way Pin
Abin4-Dec-03 13:27
Abin4-Dec-03 13:27 
GeneralUpdateLayeredWindow() Help !!! Pin
4-Dec-03 8:50
suss4-Dec-03 8:50 
GeneralLastest beta of Visual Studio .NET Pin
Robert Buldoc4-Dec-03 7:54
Robert Buldoc4-Dec-03 7:54 
GeneralRe: Lastest beta of Visual Studio .NET Pin
Mike Dimmick5-Dec-03 0:23
Mike Dimmick5-Dec-03 0:23 
GeneralRe: Lastest beta of Visual Studio .NET Pin
Robert Buldoc5-Dec-03 21:05
Robert Buldoc5-Dec-03 21:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.