Concurrency question about a program running in the OS

Here is what I know about concurrency in the OS.

To start multitasking in the OS, the CPU will allocate a time interval for each task. When performing task A, the other task will be "sleeping", etc.

Here is my question:

I have a timer program that counts on keyboard / mouse inaction. If inactivity continues for 15 minutes, a splash screen pop-up will appear.

If the concurrency theory is given above, will the timer be inaccurate? Since each program running in the OS will have some “sleep” time, then the timer program also has a chance to “sleep”, but in the real world time does not stop.

+5
source share
6 answers

, , . , , , .

+1

, , - ( ).

AnthonyWJones, .

, - .

+1

, :

  • activityTime = [ ]
  • now = [ ]
  • >= 15 ActivityTime,
  • 1

1 2 , - , , .

+1

. Java . , " " . , , , , , . , , , .

0

See for example http://www.opengroup.org/onlinepubs/000095399/functions/sleep.html

The pause time may be longer than required due to the planning of other activities by the system.

0
source

The time indicated in sleep()is indicated in real time, not the processor time that your process uses. (Since the processor time is approximately 0 when your program sleeps.)

0
source

All Articles