#include stdafx.h #include #include #include DWORD WINAPI thread1 (void *); DWORD WINAPI thread2 (void *); DWORD main...
Question:
#include "stdafx.h"
#include
#include
#include
DWORD WINAPI thread1 (void *);
DWORD WINAPI thread2 (void *);
DWORD main (DWORD argc, LPTSTR argv [])
{
DWORD ThId;
HANDLE thread1_h, thread2_h;
/* Create the two threads. */
thread1_h = CreateThread (NULL,0, thread1, NULL, 0, &ThId);
thread2_h = CreateThread (NULL,0, thread2, NULL, 0, &ThId);
/* Wait for the two threads to complete.*/
WaitForSingleObject (thread1_h, INFINITE);
WaitForSingleObject (thread2_h, INFINITE);
printf ("thread1 and thread2 threadsterminated");
return 0;
}
DWORD WINAPI thread1 (void *arg)
{
for(int i=0;i<10;i++)
printf("###############");
return 0;
}
DWORD WINAPI thread2 (void *arg)
{
for(int j=0;j<10;j++)
printf("***************");
return 0;
}
-----------------------------------------------------------------------------------------
LAB Assignment
Write a program that runs two threads,each one of them prints on the screen a counter value (which startsfrom 0 until a user input value(20 for example)) associated withits thread ID. Make an infinite loop in the main program associatedwith a sleep function to print the state of each thread.
Print the output screen which will have
- states (by main) and
- counter/threadID (by threads).
Repeat the above two times and observe the order of execution ofeach thread and comment.