06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

4.2 Exercise 2 – Lab 1 preparation<br />

4.2. Exercise 2 – Lab 1 preparation<br />

In this exercise you will design a real-time system for an alarm clock application<br />

using threads, semaphores and provided hardware interfaces. In lab 1<br />

you will implement your design (the implementation usually takes longer than<br />

two hours so be sure to start well in advance of the lab occasion). Study the<br />

provided specification, description of the handout code and hardware emulator<br />

and answer the following questions (express your design in class diagrams<br />

and Java code where necessary):<br />

1. What parallel activities are needed, i.e., which thread objects do you<br />

need?<br />

2. What common data need to be shared between threads? Where is the<br />

data to be stored?<br />

3. What operations on data are needed for each thread? Where should this<br />

logic be stored?<br />

4. Where will data be accessed concurrently from different threads, i.e.<br />

where do you need to provide mutual exclusion?<br />

5. Are there other situations in the alarm clock where semaphores are<br />

needed for synchronization?<br />

Hint: study the ClockInput class.<br />

6. If you in a thread wait for the next second by simply calling sleep(1000),<br />

what will the effect on the clock time be? Is this ok for alarm clock time<br />

updating? Can it be improved?<br />

Specification<br />

1. The displayed clock time should be updated every second (by calling<br />

the ClockOutput.showTime method). Note: when the user has selected<br />

set alarm or set time, the hardware/emulator shows the set time and an<br />

update of the clock time will have no effect on the clock display. Still,<br />

the clock time should be updated every second regardless of mode.<br />

2. It should be possible to set the clock time and the alarm time. The hardware/emulator<br />

internally handles the actual setting/editing of the time<br />

value. When the user selects another mode, the set value is written to<br />

the ClockInput object and give is called for its semaphore. For example,<br />

the user selects set alarm and edits (using number keys or arrows) the<br />

alarm time. Nothing needs to be done by the control software. Then<br />

the user selects set time and the alarm time is written to the ClockInput<br />

103

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

Saved successfully!

Ooh no, something went wrong!