Click here to Skip to main content
15,913,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Determining privilege levels of running process Pin
Daniel Lohmann18-Aug-02 10:19
Daniel Lohmann18-Aug-02 10:19 
GeneralUsing MSDN from .NET with MSVC6 Pin
Marcin Jakubowski18-Aug-02 4:52
Marcin Jakubowski18-Aug-02 4:52 
GeneralRe: Using MSDN from .NET with MSVC6 Pin
Michael P Butler18-Aug-02 8:11
Michael P Butler18-Aug-02 8:11 
GeneralDebug Assertion in Debug DLL (not Release) Pin
User 665818-Aug-02 3:45
User 665818-Aug-02 3:45 
GeneralRe: Debug Assertion in Debug DLL (not Release) Pin
User 665818-Aug-02 4:11
User 665818-Aug-02 4:11 
GeneralRe: Debug Assertion in Debug DLL (not Release) Pin
Chris Losinger18-Aug-02 17:34
professionalChris Losinger18-Aug-02 17:34 
GeneralRe: Debug Assertion in Debug DLL (not Release) Pin
Mustafa Demirhan19-Aug-02 13:51
Mustafa Demirhan19-Aug-02 13:51 
GeneralProblem with monitoring threads !!! Pin
tongc18-Aug-02 3:41
tongc18-Aug-02 3:41 
Hi !!

I have 5 threads that takes the milisecond that take 10000, 15000, 20000, 25000, 30000 milisecond as parameter respectively. In the main thread i pass these parameter to the CreateThread function, then display how many threads are still running every second. It seems working seamlessly, but when i really notice, the first thread which I pass 5000 milisecond in only display 9 times(it should be 10 times), whereas the thread with 250000 as parameter is displayed 6 times. Where as each thread is 5 units away each the other.

this is my code
INT volatile runningThread = 5;	//number of running thread.

void Thread(DWORD time)	
{
	
	Sleep(time);
	
}

void main()
{

	INT i;
	HANDLE handle[5];
	DWORD threadID[5];

	DWORD time[5];
	time[0] = 10000;
	time[1] = 15000;
	time[2] = 20000;
	time[3] = 25000;
	time[4] = 30000;

	BOOL flag[5];
	for(i = 0; i < 5; i++)
		flag[i] = TRUE;
	
	for(i = 0; i < 5; i++)
	{
		handle [i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Thread 
									, (VOID *)time[i], NULL, &threadID[i]);
		
		if (handle[i] == 0)
			cout << "Create thread " << i << "failed " << GetLastError() << endl;
		
		cout << threadID[i] << endl;
	}
	
	while(WaitForMultipleObjects(5, handle, TRUE, 1000) == WAIT_TIMEOUT)
	{
		for (i = 0; i < 5 ; i++)
		{
			if(WaitForSingleObject(handle[i], 0) == WAIT_OBJECT_0 && flag[i] == TRUE)
			{
				runningThread--;
				flag[i] = FALSE;
			}
		}
		printf(" %d ", runningThread);
	}
	
	
	for(i = 0; i <5; i++)
	{
		if(!CloseHandle(handle[i]))
			cerr << "Failed to close process. Error number" << GetLastError() << endl;
		
	}

	cout << "\nAll threads have been terminated " << endl;


thanks in advance!!!

ADDED(after modification) : I've noticed one thing, that is if i debug it step by step (F11) then it works ok, but when running Ctrl+F5 it just doesnt seem run right!!!
GeneralRe: Problem with monitoring threads !!! Pin
valikac18-Aug-02 9:41
valikac18-Aug-02 9:41 
GeneralRe: Problem with monitoring threads !!! Pin
Daniel Lohmann18-Aug-02 10:34
Daniel Lohmann18-Aug-02 10:34 
GeneralRe: Problem with monitoring threads !!! Pin
tongc18-Aug-02 16:41
tongc18-Aug-02 16:41 
GeneralRe: Problem with monitoring threads !!! Pin
Daniel Lohmann19-Aug-02 1:12
Daniel Lohmann19-Aug-02 1:12 
GeneralRe: Problem with monitoring threads !!! Pin
tongc20-Aug-02 5:19
tongc20-Aug-02 5:19 
GeneralRe: Problem with monitoring threads !!! Pin
Daniel Lohmann20-Aug-02 8:32
Daniel Lohmann20-Aug-02 8:32 
GeneralRe: Problem with monitoring threads !!! Pin
Mustafa Demirhan19-Aug-02 13:56
Mustafa Demirhan19-Aug-02 13:56 
GeneralHot/mouseover Pin
DanYELL18-Aug-02 3:33
DanYELL18-Aug-02 3:33 
Questionexcepting a flag???? Pin
Eric Cashwell18-Aug-02 2:39
Eric Cashwell18-Aug-02 2:39 
AnswerRe: excepting a flag???? Pin
tongc18-Aug-02 3:09
tongc18-Aug-02 3:09 
GeneralRe: excepting a flag???? Pin
Eric Cashwell18-Aug-02 3:15
Eric Cashwell18-Aug-02 3:15 
GeneralRe: excepting a flag???? Pin
Eric Cashwell18-Aug-02 4:25
Eric Cashwell18-Aug-02 4:25 
GeneralEasy question (hopefully) Pin
Jh318-Aug-02 2:17
Jh318-Aug-02 2:17 
GeneralRe: Easy question (hopefully) Pin
Stephane Rodriguez.18-Aug-02 2:26
Stephane Rodriguez.18-Aug-02 2:26 
GeneralRe: Easy question (hopefully) Pin
tongc18-Aug-02 3:44
tongc18-Aug-02 3:44 
GeneralAppendChunk question - simple probably Pin
nss17-Aug-02 23:28
nss17-Aug-02 23:28 
GeneralRe: AppendChunk question - simple probably Pin
Joel Lucsy19-Aug-02 3:49
Joel Lucsy19-Aug-02 3:49 

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.