Common Issues

Polling/Busy Waiting

What is polling and what is not is a hard question. We here give some examples in pseudo code. Loops that reduce to something similar to the situation below (where the dots do not include any blocking wait) must be considered as polling.

while (e) { # POLLING!
   ...
   sleep(t); 
   ...
}

Using a blocking operation within a loop is not considered as polling.

while (e) { # NO POLLING!
   ...
   wait(o);
   ...
}

if it is not the case that something is regularly waking the process from its wait. Thus, the following example must be considered as an instance of polling:

obj o;

process a {   
  while (true) { 
    sleep(t);
    notify(o);
  }
}

process b {  # POLLING!
  while (e) {
    wait(o);
  }
}

When using message passing in JR the most common cause of busy-waiting loops is a wrong use of the else branch in an input statement. Here is a fine example of a busy-waiting loop:

  while (true)
     inni void message() { ... }
        ...
     [] else {
          // Just loop again if nothing was to be serviced.
        }
Last modified: Monday, 21-Jan-2013 16:14:31 CET
COMPUTER SCIENCE AND ENGINEERING - Chalmers University of Technology and Göteborg University
SE-412 96 Göteborg, Sweden - Tel: +46 (0)31- 772 1000