Skip to content

Joannapapad/pthreads-order-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Pizza Store Simulation (C / pthreads)

About

This project is a simulation of a pizza store implemented in C using pthreads. Each customer order runs as a separate thread, and the program models how orders are handled under limited resources (staff and equipment).

The goal was to practice multithreading, synchronization, and handling shared resources in a realistic scenario.


How it works

Each order goes through the following steps:

  • A customer calls the store (telephone operator needed)

  • Payment is processed (there is a small chance it fails)

  • If successful:

    • A cook prepares the order
    • Ovens are used for baking
    • The order is packed
    • A deliverer delivers it

All of these steps depend on resource availability, so threads may block and wait.


Resources in the simulation

  • 2 telephone operators
  • 2 cooks
  • 10 ovens
  • 10 deliverers

What it tracks

At the end of the simulation, the program prints:

  • Total income
  • Successful and failed orders
  • Number of pizzas per type
  • Average and max delivery time
  • Average and max cooling time

Compile and run

Compile

gcc -o pizza program.c -lpthread

Run

./pizza <customers> <seed>

Example:

./pizza 50 1234

Notes

  • Randomness is used for order timing, payment success, and delivery time
  • Mutexes and condition variables are used to handle shared resources
  • The program assumes all time values are in seconds (simulating minutes)

Why I made this

This was part of a project to get more comfortable with:

  • pthreads
  • synchronization (mutexes / condition variables)
  • designing systems where multiple things happen at the same time

Possible improvements

  • Clean up global variables
  • Improve thread-safe random number generation
  • Add logging instead of just printing
  • Better structure (split into multiple files)

Author

Joanna Papadakaki

About

C-based simulation of a pizza store using pthreads, focusing on multithreading, synchronization, and shared resource management (operators, cooks, ovens, deliverers).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages