21.08.2013 Views

A State-Based Programming Model for Wireless Sensor Networks

A State-Based Programming Model for Wireless Sensor Networks

A State-Based Programming Model for Wireless Sensor Networks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

46 Chapter 3. <strong>Programming</strong> and Runtime Environments<br />

Actual implementations of over-the-air programming often require the cooperation<br />

of user-written application code. Over-the-air reprogramming is often<br />

provided as a substitute <strong>for</strong> dynamic process loading by several resourceconstrained<br />

sensor-node architectures. It has been deployed, <strong>for</strong> example, in<br />

BTnode system software [21], BTnut [123], TinyOS [45]), Maté [79], and others.<br />

A detailed survey of software update management techniques can be found<br />

in [51].<br />

3.4.4 Process Concurrency<br />

In a concurrent process model, several processes can run at the same time. Since<br />

wireless sensor nodes are typically single-processor systems, concurrent processes<br />

need to be interleaved, with the processor multiplexed among them. Processor<br />

multiplexing is called scheduling and is typically per<strong>for</strong>med by the system<br />

software as it is considered a fundamental system service. The points in<br />

the programs where switching is best per<strong>for</strong>med depends on the programs’ internal<br />

structure. There<strong>for</strong>e, scheduling mechanisms are closely related to programming<br />

models and their corresponding execution environments. For sensor<br />

nodes two basic scheduling strategies exist. Architectures with an event-driven<br />

execution environment typically provide a concurrency model that is also based<br />

on events. Systems with a multi-threaded execution environment provide a concurrency<br />

model based on context switches.<br />

Context-Switching Processes<br />

The design of process concurrency based on context switches <strong>for</strong> sensor nodes<br />

can be best understood by comparing it to designs in general-purpose operating<br />

systems.<br />

Multi-tasking in general-purpose operating systems. Modern general-purpose<br />

operating systems have two levels of concurrency—the first level among processes,<br />

and the second level among the threads within a process. Both levels<br />

have their own scheduling mechanism, which are both based on context<br />

switches. Context-switching processes is referred to as multi-tasking. (The terms<br />

task and process are often used synonymously.)<br />

Multi-threading and multi-tasking are similar in many respects but differ in<br />

the way they share resources. They both provide concurrency, the <strong>for</strong>mer among<br />

the threads of a process, the latter among the processes running on a system.<br />

Just like threads, tasks have their own sequential control flow and their own<br />

context. And just like multi-threading, multi-tasking requires context switches<br />

and individual stacks (one per task) to store context in<strong>for</strong>mation. There<strong>for</strong>e, the<br />

system support required <strong>for</strong> multi-tasking is also very similar to that of multithreading,<br />

which we discussed previously in Sect. 3.2.4 on page 38.<br />

The main difference to threads is that tasks typically do not share resources,<br />

such as files handles and network connections. In particular, tasks have their<br />

own memory regions that are protected against accidental access from other<br />

tasks. This is desirable to protect correct programs from buggy ones. To provide<br />

communication and synchronization amongst processes despite those protec-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!