Skip to content

Instantly share code, notes, and snippets.

@adurpas
Created December 3, 2012 14:39
Show Gist options
  • Save adurpas/4195400 to your computer and use it in GitHub Desktop.
Save adurpas/4195400 to your computer and use it in GitHub Desktop.
// ISU laboratory session #8, exercise #3.
#include <osapi/Thread.hpp>
#include <osapi/Message.hpp>
#include <osapi/MsgQueue.hpp>
#include "car.hpp"
#include "EntryGuard.hpp"
#include "ExitGuard.hpp"
#include <unistd.h>
#include <iostream>
#define NUMBER_OF_CARS 5
#define QUEUE_SIZE 5
using namespace std;
int main()
{
//Creating entry Thread
entryGuard entryGuardObj(QUEUE_SIZE);
osapi::Thread entryGuardThread(&entryGuardObj);
entryGuardThread.start();
//Creating exit Thread
exitGuard exitGuardObj(QUEUE_SIZE);
osapi::Thread exitGuardThread(&exitGuardObj);
exitGuardThread.start();
//Creating car Threads
for(int i=0; i<NUMBER_OF_CARS; i++)
{
car* carObj = new car(i+1, QUEUE_SIZE, &entryGuardObj, &exitGuardObj);
osapi::Thread carThread(carObj);
carThread.start();
carObj->getMsgQueue()->send(car::ID_CAR_START_IND);
}
exitGuardThread.join();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment