mbed_example / Mbed OS events_ex_3
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed_events.h"
00002 #include <stdio.h>
00003 
00004 /**
00005 Event queues easily align with module boundaries, where internal state can be 
00006 implicitly synchronized through event dispatch. Multiple modules can use 
00007 independent event queues, but still be composed through the EventQueue::chain function.
00008 **/
00009 
00010 int main() {
00011     // Create some event queues with pending events
00012     EventQueue a;
00013     a.call(printf, "hello from a!\n");
00014     
00015     EventQueue b;
00016     b.call(printf, "hello from b!\n");
00017     
00018     EventQueue c;
00019     c.call(printf, "hello from c!\n");
00020     
00021     // Chain c and b onto a's event queue. Both c and b will be dispatched
00022     // in the context of a's dispatch function.
00023     c.chain(&a);
00024     b.chain(&a);
00025     
00026     // Dispatching a will in turn dispatch b and c, printing hello from
00027     // all three queues
00028     a.dispatch();
00029 }