Skip to main content Accessibility help
×
Hostname: page-component-84b7d79bbc-lrf7s Total loading time: 0 Render date: 2024-07-27T23:25:27.877Z Has data issue: false hasContentIssue false

Appendix C - Pseudocode Templates for Concurrent Tasks

Published online by Cambridge University Press:  05 March 2016

Hassan Gomaa
Affiliation:
George Mason University, Virginia
Get access

Summary

This appendix provides pseudocode templates of the event sequencing logic for the different kinds of concurrent tasks described in Chapter 13 of this textbook. These templates include event driven input tasks; periodic input and algorithm tasks; and demand driven general purpose, coordinator, output, user interaction, and state dependent control tasks.

PSEUDOCODE FOR EVENT DRIVEN INPUT TASK

An event driven input task is needed when there is an event driven (also referred to as interrupt-driven) input device to which the system has to interface (Section 13.3.2). The event driven I/O task is activated by an external event (such as an interrupt) from the device, reads the input data, does any necessary processing of the data, including sending a message to a consumer or updating a passive entity object, and then waits for the next external event.

Initialize input device, if needed;

loop

–– Wait for external event from input device;

wait (inputEvent);

read input data;

if data is recognized

then –– Process data;

convert data to internal format if needed,

e.g., convert analog data to engineering units;

process data, if needed;

prepare message containing message name and optional parameters

–– send message to consumer task via connector;

aConnector.send (message);

else –– input was not recognized;

Handle error case;

end if;

end loop;

PSEUDOCODE FOR PERIODIC INPUT TASK

A periodic input task interfaces with a passive input device, where the device is polled on a regular basis (Section 13.3.3). The periodic input task is activated by a timer event, reads the sampled input data, does any necessary processing of the data, and then waits for the next timer event. The task's period is the time between successive activations.

Initialize input device, if needed;

loop

–– Wait for timer event;

wait (timerEvent);

read input data sample;

if data is recognized

then –– Process input data;

convert data to internal format if needed,

e.g., convert analog data to engineering units;

If Boolean data, check if data has changed from previous reading;

process data, if needed;

prepare message containing message name and optional parameters

–– send message to consumer or write to data repository;

dataRepository.update(newData);

else –– input was not recognized;

Handle error case;

end if;

end loop;

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×