I have created a shared object and access it from two different program and measuring the time.
DATA array is the shared object between two processes.
Case 1: Use of while inside program1
program1 :
access shared DATA array ;// to load into memory and avoid page fault during access time calculation
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program1, Time1=%d\n",Time_needed);
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program1, Time2=%d\n",Time_needed);
while(1){}; // I replace this by sleep(1000) in CASE-2
Program2 :
access shared DATA array ;// to load into memory and avoid page fault during access time calculation
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program2, Time1=%d\n",Time_needed);
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program2, Time1=%d\n",Time_needed);
OUTPUT : First I run program1, then Program2
Inside Program1, Time1 = 17620
Inside Program1, Time1 = 17680
Inside Program2, Time1 = 7620
Inside Program2, Time1 = 7600
Case 2: Use of sleep() inside program1
program1 :
access shared DATA array ;// to load into memory and avoid page fault during access time calculation
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program1, Time1=%d\n",Time_needed);
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program1, Time2=%d\n",Time_needed);
sleep(1000);
Program2 :
access shared DATA array ;// to load into memory and avoid page fault during access time calculation
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program2, Time1=%d\n",Time_needed);
start=timer;
access shared DATA array
end=timer;
Time_needed= end-start
printf("Inside Program2, Time1=%d\n",Time_needed);
OUTPUT : First I run program1, then Program2
Inside Program1, Time1 = 17620
Inside Program1, Time1 = 17680
Inside Program2, Time1 = 17620
Inside Program2, Time1 = 17600
From the output in case -1, I can say shared data DATA array is loaded into memory/cache by 1st program and second program access it from cache. Whereas this also true for CASE-2, but the result looks like it is flushed out from cache while Program1 goes into sleep.
I am using GCC under linux.
Any clue ? Thanks in advance .