https://github.com/artistrea/concurrency-project
The objective is to explore concurrency.
A noble ball will be implemented with the following specs:
-
The nobles and king arrive with a predetermined list of actions to do;
-
The king has the following actions/states:
- Talk to a noble
- He may summon any noble
M
; - If he doesn't specify a noble (
M=-1
), he chooses the next noble waiting on queue; - If he doesn't specify a noble and there are no nobles on queue, he summons a random noble;
- The nobles have at most 1 second to present themselves;
- He may summon any noble
- Idle
- King is simply idle;
- End ball
- Should end program;
- Talk to a noble
-
A noble has the following actions/states and reactions:
- Talk to the king
- He enters a queue to talk to the king;
- If king selected him to talk to, he presents himself to the king;
- Waits for king dismissal;
- Reactions:
- If waiting on the queue and
[KING END BALL]
, then[NOBLE END BALL]
- If waiting on the queue and
[KING SUMMONS]
him occurs or already occurred, then present himself to king;
- If waiting on the queue and
- Talk to another noble
- He may "ask" another noble
M
to talk; - He may wait until
T
seconds for nobleM
to answer; - They talk for
X
seconds; - Reactions:
[KING END BALL]
, then[NOBLE END BALL]
- If, at any time,
[KING SUMMONS]
one of the nobles, 1[NOBLE TALK TO KING]
and 1 abandons action and goes to next action;
- He may "ask" another noble
- Idle
- Noble is idle for a certain duration;
- Reactions:
[KING SUMMONS]
, then[NOBLE TALK TO KING]
[KING END BALL]
, then[NOBLE END BALL]
[NOBLE TALK TO]
request, then[NOBLE TALK TO]
using the request to build parameters
- Noble end ball
- Noble should leave the ball;
- Talk to the king
There are functions called king_spawn
and noble_spawn
that spawn the king and the nobles present in the ball.
Each one receives a default actions sequence, that may change according to other nobles actions, to the kings requests, and to the environment.
Look at src/main.c
to see more.
To build the executable to ./bin
make
To build debug version:
# WARNING: you may need to run `make clean` if the *.o files were already built without debug
make debug
Then you can run the executable through:
./bin
Or, if you built for debug:
gdb ./bin