3.11 Example 10

Many of the points which have been introduced above are collected in the following procedure:

  2134 setrun (p)
       {
         register struct proc *rp;
         rp = p;
         rp->p_wchan = 0;
         rp->p_stat = SRUN;
         if (rp->p_pri < curpri)
           runrun++;
         if (runout != 0 &&
             (rp->p_flag & SLOAD) == 0) {
            runout = 0;
            wakeup (&runout);
         }
       }

Check your understanding of “C” by figuring out what this one does.

There are two additional features you may need to know about:

“&&” is the logical conjunction (“and”) for relational expressions. (Cf. “||” introduced earlier.)

The last statement contains the expression

    &runout

which is syntactically an address variable but semantically just a unique bit pattern.

This is an example of a device which is used throughout UNIX. The programmer needed a unique bit pattern for a particular purpose. The exact value did not matter as long as it was unique. An adequate solution to the problem was to use the address of a suitable global variable.