Git Product home page Git Product logo

threading_test's Introduction

C++ Threading Test

A quick C++ threading test where data is passed between different threads - producer and consumer - while remaining thread-safe. This is achieved using the standard C++ library only and has to be fast. As such the move operator has been used as part of the demonstration as well.

Notes

  • The code has three threads: main, producer and consumer. The main thread waits till all the other threads are finished. The consumer waits for the producer to be finished. And the producer produces the SEND_MESSAGES number of messages.
  • The code assumes the main thread keeps running while the other threads are active. If this is not the case an exception may be thrown in both the producer and consumer threads. The resulting behavior is undefined.
  • Mutexes and file output is made thread-safe using RAII.
  • The buffers in the messages are guaranteed to be freed. This is done by using RAII to delete the data on an exception and using move instead of copy when pushing message into and popping them out of the vector. Essentially transfering ownership not only of the object but the buffer too. (Keep in mind that if the main thread terminates before the producer or consumer this behavior becomes undefined.)

threading_test's People

Contributors

scillman 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.