CS Operating Systems HOMEWORK
Table 1:
Job # Arrival Time CPU time
1 8:00 18
2 8:10 16
3 8:20 4
Spring 2017, COMP4100 H/W-2 (2/1) Name: Due date (2/8)
1. The arrival time and CPU minutes needed for job 1, 2, and 3 are shown in the Table 1. Their I/O wait are all 40
percent. What time does each job run to completion?
2. The following is the sample code for multithreading. Run it and explain how it works. Pick up one of the programs that you generated so far (for any assignment, not limited to CPM4100), and modify
it into multithreaded version.
//----------------------------------------------------------------------- // Windows multithreading sample code //-----------------------------------------------------------------------
#include "stdafx.h" #include <stdio.h> #include <windows.h> #include <process.h> // needed for _beginthread() void ThreadFunc2( void *arg ) {
printf( "Received Parameter = %d\n", (int)arg); int Count2 = 0; while ( Count2 < 10 ) { printf( "In second thread, %d\n", Count2); Count2++; Sleep( 100 ); } } void ThreadFunc3( void *arg ) { printf( "Received Parameter = %d\n", (int)arg); int Count3 = 0; while ( Count3 < 10 ) { printf( "In third thread, %d\n", Count3); Count3++; Sleep( 250 ); } } int _tmain(int argc, _TCHAR* argv[]) { printf( "Now in the main() function.\n" ); _beginthread( ThreadFunc2, 0, (void*)2 ); _beginthread( ThreadFunc3, 0, (void*)3 ); // From here on there are three separate threads executing // our one program. Sleep( 10000 ); return 0; }