Last change
on this file since 3f37f5b was
84334d0,
checked in by caparsons <caparson@…>, 15 months ago
|
refactored thesis actor code to use new lowercase allocation enum name
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[601bd9e] | 1 | #include <stdio.h> |
---|
| 2 | #include <string.h> |
---|
| 3 | #include <actor.hfa> |
---|
| 4 | |
---|
| 5 | struct derived_actor { |
---|
| 6 | inline actor; // Plan-9 C nominal inheritance |
---|
| 7 | }; |
---|
| 8 | void ?{}( derived_actor & this ) { // Default constructor definition |
---|
| 9 | ((actor &)this){}; // Call to actor constructor |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | struct derived_msg { |
---|
| 13 | inline message; // Plan-9 C nominal inheritance |
---|
| 14 | char word[12]; |
---|
| 15 | }; |
---|
| 16 | void ?{}( derived_msg & this, char * new_word ) { // Overload constructor definition |
---|
| 17 | ((message &) this){ Finished }; // Call to message constructor passing allocation status |
---|
| 18 | strcpy(this.word, new_word); |
---|
| 19 | } |
---|
| 20 | |
---|
[84334d0] | 21 | allocation receive( derived_actor & receiver, derived_msg & msg ) { |
---|
[601bd9e] | 22 | printf("The message contained the string: %s\n", msg.word); |
---|
| 23 | return Finished; // Return allocation status of Finished now that the actor is done work |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | int main() { |
---|
| 27 | start_actor_system(); // Sets up executor. Actors and messages can be created after this point. |
---|
| 28 | derived_actor my_actor; |
---|
| 29 | derived_msg my_msg{ "Hello World" }; // Constructor call |
---|
| 30 | my_actor | my_msg; // All message sends are done through the bar operator |
---|
| 31 | stop_actor_system(); // Waits until all actors are finished |
---|
| 32 | return 0; |
---|
| 33 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.