Skip to main content Accessibility help
×
Hostname: page-component-84b7d79bbc-l82ql Total loading time: 0 Render date: 2024-07-29T04:35:43.553Z Has data issue: false hasContentIssue false

11 - Concurrency

Published online by Cambridge University Press:  05 August 2012

Philip Levis
Affiliation:
Stanford University, California
David Gay
Affiliation:
Intel Research, Berkeley
Get access

Summary

So far, the code we've lookedat has been split-phase andruns in tasks (synchronous). This programming model is sufficient for almost all application-level code. High-performance applications and low-level device drivers sometimes require additional functionality and concurrency models. This chapter describes two such additional mechanisms: asynchronous code and resource locks. Asynchronous code is a feature of the nesC language, while resource locks are a set of TinyOS components and mechanisms.

Asynchronous code

Tasks allow software components to emulate the split-phase behavior of hardware. But they have much greater utility than that. They also provide a mechanism to manage preemption in the system. Because tasks run atomically with respect to one another, code that runs only in tasks can be rather simple: there's no danger of another execution suddenly taking over and modifying data under you. However, interrupts do exactly that: they interrupt the current execution and start running preemptively.

The async keyword

As we saw in Chapter 5, nesC distinguishes between synchronous (sync) and asynchronous (async) code. Commands and events that can run preemptively from interrupt handlers (and therefore asynchronously with regards to tasks), must be labeled with the async keyword, both in the interface where the command or event is declared and in the module where the command or event is implemented. As a result, an async command or event, or a function reachable from an async command or event can only call or signal async commands and events (nesC will tell you when you break this rule). This rule means that it's clear from looking at an interface or module which code is synchronous and which is asynchronous.

Type
Chapter
Information
TinyOS Programming , pp. 192 - 205
Publisher: Cambridge University Press
Print publication year: 2009

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.

  • Concurrency
  • Philip Levis, Stanford University, California, David Gay
  • Book: TinyOS Programming
  • Online publication: 05 August 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511626609.013
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.

  • Concurrency
  • Philip Levis, Stanford University, California, David Gay
  • Book: TinyOS Programming
  • Online publication: 05 August 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511626609.013
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.

  • Concurrency
  • Philip Levis, Stanford University, California, David Gay
  • Book: TinyOS Programming
  • Online publication: 05 August 2012
  • Chapter DOI: https://doi.org/10.1017/CBO9780511626609.013
Available formats
×