Skip to content

About

Implementation of certain variant of roller coaster synchronization problem uttilizing POSIX via C libraries.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

Informations about project

Project contains implementation of one of the variants of the rollercoaster synchronization problem using POSIX semaphores.

The solution is based on assignment from Operating Systems course at BUT FIT.

The main focus of this project was to try implementing a rollercoaster synchronization problem using semaphores in C programming language.

Detailed informations

The program checks arguments from user and runs a rollercoaster simulation consisting of dispatcher, carts and visitor child processes of the program.

The dispatcher is process only responsible for keeping track of how many visitors can enter carts and giving carts signals to board. When there are no more visitors in line, signals all carts to end and ends itself.

The carts wait for dispacther signal, post signals for visitors and await their response. One cart may be used multiple times however there is no guarantee it will ever be used. Carts lifecycle ends after dispatcher signal.

The visitors enter the attraction, wait for carts, ride the rollercoaster and then just end themselves.

Each process class has certain actions that sneds output to 'log.out' file, which gets created during the programs runtime.

Project structure

project/
├── proc_main.c
├── proc_entities.h
├── proc_entities.c
├── proc_input.h
├── proc_input.c
├── Makefile
├── tests/
│   └── tests.py
└── README.md

proc_main.c - main file

proc_input.h, proc_input.c - library containing methods for checking program input

proc_entities.h, proc_entities.c - library containing structures, macros, and process functions

tests.py - contains tests for the program

Running the project

  1. Build the program by using "make" method of Makefile

  2. Run the project in terminal by command ./proc_main CART VIS CART_CAP CART_TIME VIS_QUEUE INTERVAL, where:

CART is number of carts (0 < CART < 10)
VIS is number of visitors (0 < VIS < 10000)
CART_CAP is number of visitors allowed in one cart (4 <= CART_CAP <= 40)
CART_TIME is minimal time cart spends driving on rollercoaster (0 <= CART_TIME <= 1000)
VIS_QUEUE is minimal time between creation and queueing visitor (0 <= VIS_QUEUE <= 1000)
INTERVAL is minimal time between two carts in microseconds (0 < INTERVAL <= 100)

(NOTE: You can change all of the variable preset limits by editing same named macros in 'proc_entities.h')
  1. You can read the output of the program either by opening the newly created "log.out" in some text editor or using command cat <log.out to print it inside terminal

Example output

1: D: started
2: D: next cart
3: C 1: started
4: C 1: boarding started
5: V 1: started
6: V 1: queue
7: V 1: boarding
8: C 1: boarding complete
9: C 1: leaving started
10: D: closing
11: V 1: leaving
12: C 1: leaving complete
13: C 1: closed

Tests

The project contains a few tests checking whether all processes were initialized and ended, alongside test for memory leak using tool valgrind. The test are written uttilizing the 'unittest' Python library

To run the tests, run make test (NOTE: you need to have pytest and valgrind installed for successful execution of tests)

Example output:

============================= test session starts ==============================
platform linux -- Python 3.13.5, pytest-8.3.5, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: censored
collected 8 items                                                              

tests.py::ArgumentsTests::test_ArgOutOfRange PASSED                      [ 12%]
tests.py::ArgumentsTests::test_InvalidArgType PASSED                     [ 25%]
tests.py::ArgumentsTests::test_InvalidCharInArg PASSED                   [ 37%]
tests.py::ArgumentsTests::test_WrongArgCount PASSED                      [ 50%]
tests.py::ProcessTests::test_EachVisitorServed PASSED                    [ 62%]
tests.py::ProcessTests::test_ProcessesCreated PASSED                     [ 75%]
tests.py::ProcessTests::test_ProcessesFinished PASSED                    [ 87%]
tests.py::MemoryLeakTest::test_MemoryClean PASSED                        [100%]

============================== 8 passed in 8.31s ===============================

Makefile

Makefile contains methods for translation of the program, alongside method for running tests and cleaning up after translation.

make - compiles program

make test - runs tests

make clean - clears all binary files created during translation alongside program output

Technologies

C Programming Language

Python Programming Language

POSIX Semaphores

valgrind -- development tool for checking memory operations (Download)

pytest -- used for more readable test message output (Download)

About

Implementation of certain variant of roller coaster synchronization problem uttilizing POSIX via C libraries.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages