Go back to the contents page or the algorithms section.
6 threads are used by the robot and they use mutex on global variables and conditions
beginnerthread() {
//contains all the movements of the robot starting as a beginner
}
finisherthread() {
//contains all the movements of the robot starting as a finisher
}
serverthread() {
//listens to the messages sent by the server
}
int main() {
//the main thread
}
On the small arena only :
positionthread() {
//determines in real time the position of the robot
}
messagethread() {
//sends the position of the robot to the server every 2 seconds
}
We also use global variables, conditions and mutexes dealing with the threads.
x_robot ( + mutex_x_robot) //the abscissa of the robot
y_robot ( + mutex_y_robot) // the ordinate of the robot
The mutexes on x_robot and y_robot are needed because both the messagethread and the positionthread use those variables.
moving ( + mutex_moving) // boolean: 0 if the robot is moving, 1 if not
The mutex is needed, because the beginner/finisher thread, the server thread and the message thread use this variable. For instance, when the robot is a beginner, when it reaches the top right corner of the arena, the beginner thread has to set moving on 1 to stop the robot, while the message thread needs the value of this variable to send the position of the robot (if moving = 1, there is no need to send the position), and the message thread is waiting for a NEXT to come in order to set moving on 0. Three threads are trying to use/modify a value at the same time, so a mutex is needed.
condition_moving
: thread condition to tell the robot when it has to move : when the condition is delivered by the server
thread to the finisher/beginner thread (when receiving a NEXT message from the server),
moving = 0 and the robot can move.
stop
is a boolean: 1 if the robot has to stop because of the server. It is modified by the message thread to tell the main thread to stop.
Go back to the contents page or the algorithms section.
Created by Sofiène Jerbi, Thibault Petitjean (@thib774) and Florian Kohler (@FlorianKohler)
OS Course, Eurecom 2k16