Giter Site home page Giter Site logo

wenxu-codinglife / multithreading-producer-consumer Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 82 KB

Implementation of the producer-consumer problem written in C++

Makefile 0.57% C++ 99.08% C 0.35%
multithreading pthread mutex conditional-variables producer-consumer-problem

multithreading-producer-consumer's Introduction

Multithreaded Producer/Consumer

This is a personal C++ project implementing a program to solve the multi-producer/multi-consumer problem. pthread, mutex, conditional variable are employed.

Producer-Consumer Problem

In this problem, we want to create p producer threads that produce n items in total, and q consumer threads consuming those items. Each producer thread produces n/p items (integer division). Any remaining items will be produces by producer thread 0.

  • A producer produces items marked with two values: the ID of the producer and a value that is determined according to the producer's id and the total number of the producers. For instance, if there are 3 producers, producer 0 will create its items in this way: (0, 0),(0, 3),(0, 6), etc.
  • A consumer consumes items and records the corresponding information.
  • Time taken by each thread will be recorded.
  • A stat will be printed as the result that can be used for verifying.

How to run

Clone this repo and enter the directory. Then type in your shell:
Compile:

$ make producer_consumer

Test the binary like this:

$ ./producer_consumer --nItems 100000 --nProducers 3 --nConsumers 5 --bufferSize 100000

Then the stat would be printed like this: demo

multithreading-producer-consumer's People

Contributors

wenxu-codinglife avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.