The Wait-Free Read Queue

WaitFreeReadQueue lets a thread accept input from another thread without waiting for the input.

The code in Example 20-2 shows the main loop in a periodic thread that accepts new period values from a wait-free write queue.

Example 20-2. Using a WaitFreeReadQueue for loose coupling
RelativeTime newPeriod;
RealtimeThread rt = currentRealtimeThread();

while(true){
    //  ****
    //  Do some work
    //  ****
    //  See if a new period has
    //  arrived on the queue.
    newPeriod = (RelativeTime)queue.read();
    //  If there is a new period,
    //  update the period in our thread
    if(newPeriod != null){
        PeriodicParameters oldParam;
        oldParam =(PeriodicParameters)
            rt.getReleaseParameters();
        oldParam.setPeriod(newPeriod);
    }
    rt.waitForNextPeriod();
}

If ...

Get Real-Time Java™ Platform Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.