For this assignment you are to write a Win32 program which implements threads and synchronizes them. The main thread of your program should spawn four threads, with thread numbers 1 to 4.
Each of the four threads should enter a loop which alternates
between a noncritical section and a critical section.
Each of the 4 threads
should read a file called datan.txt where
n is the thread number. These files will consist
of a list of space delimited integers. These will tell the
thread how many seconds to be in the Non Critical section and
the critical section. For example, if the file looked
like this
7 3 5 1 2 4
That thread would spend seven seconds in its NonCritical Section,
then three seconds in its critical section, then five seconds in
its NonCritical Section, then one second in its critical section,
then two seconds in its NonCritical Section, then four seconds in
its critical section, then it should return. The return value
should be the total time spent in its critical section (i.e. the
sum of the even numbered values).
Naturally, only one thread at a time should be in its critical
section. Each thread should display the statement:
Thread n is entering its critical section
as it enters its critical section, and
Thread n is leaving its critical section
when it leaves its critical section.
You can control the time spent in each function with the Sleep() API. This takes an integer as an argument and sleeps for that many milliseconds, (so you should multiply the value in the file times 1000).
Here are four files that you can use to test your program. We will test your program using different files.
Data0.txt
4 5 6 7 10 3
Data1.txt
1 1 2 3 4 5 6 7
Data2.txt
2 4 6 8 10 12 10 8
Data3.txt
6 3 8 4 7 5 12 2