Giter Site home page Giter Site logo

priorityqueue_lib's Introduction

Thread-Safe Preemptive Priority Queue in C++

A C++ implementation of a custom priority queue designed for multi-threaded environments.

Introduction

This repository presents a custom implementation of a priority queue with specialized behaviors:

  • Generic Type (T): The priority queue is type-agnostic.
  • Priority-based: Each item comes with a priority, "1" being the highest.
  • Throttle Rate: A built-in mechanism to ensure a mix of priorities during deque operations.
  • Thread Safety: Designed specifically for multi-threaded environments.

Features

  • Fixed Size: The queue has a pre-determined size.
  • Producer-Consumer Constraints:
    • If the queue is full, any producer thread trying to add to it is blocked until space becomes available.
    • If the queue is empty, any consumer thread trying to retrieve an item is blocked until an item becomes available.
  • Preemptive Modes: Includes mechanisms to prevent lower-priority items from getting stuck indefinitely:
    • Aging: Increases the priority of all items.
    • Next Priority Activation: Temporarily changes the throttle rate.

How to Use

  1. Include the PriorityQueue.h header in your project.
  2. Create an instance of the priority queue specifying the desired max size, throttle rate, preemptive size, and preemptive mode.
  3. Use the push and pop methods to add and retrieve items, respectively.

Sample Usage

#include "PriorityQueue.h"

int main() {
    PriorityQueue<int> pq(100);  // create a priority queue with a max size of 100

    pq.push(5, 1);  // push item with value 5 and priority 1
    int val = pq.pop();  // retrieves the item with the highest priority
}

Debugging

To inspect the current state of the priority queue, you can use the _display() method. This is particularly helpful during development to understand the internal dynamics.

pq._display();

priorityqueue_lib's People

Contributors

shingyipcheung avatar

Watchers

James Cloos 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.