Coder Social home page Coder Social logo

althread's Introduction

ALthread library

A limited threading space in c++

#what is it? A simple to use library which contains a class for bookeeping a multi-threading enviornment - ever wanted to spawn a lot of threads because it's how things are meant to be done but worry about the performance of multi-threading because the functions are taking a lot cpu time to get things done - with just a header file you can create a sort-of-imaginary space where you threads will be running in and anytime the number of running threads exceeds the number specified by the client it will wait untill a thread is available in the thresh hold again.

#how to implement> the header file provides two methods, initiate() and booker(). initiate takes an integer constant and set the thresh hold for the number of threads that is allow to use in the space spawned by booker(), the booker() after being called will set the Index_of_threads variable to a number as long there are free spots in the thresh hold. You will need to initiate the class first *do it in global to avoid stack overflow, and then set the threading space by calling initiate(int x) with int x being a constant integer that you want the limit to be (like initiate(42)), you should also initiate a std::thread class with an aray ( such as std::thread abc[1024] ) with the number to be whatever but must equal or larger to the value of the limit of space that you want to implement. then in the rest of your codes, whenever you want to spawn a thread, use the thread arays you created in global, with Index_of_threads to be the aray number, like abc[efghijk.Index_of_threads], then you will need to set a class variable in whatever function you want to do multi-threading to 1, like this : efghijk.thread_id[efghijk.Index_of_threads] = 1; //And now you can spawn threads whenever you feel like you want to multithread something knowing that it will always run at a limited number of threads at any given time.

~Example codes: (a.cpp)

#include "ALthread.h"
using namespace std;

std:thread abc[8192];




 ALthread start_abc;


void hello_world ()
{
//do soemthing
start_abc.thread_id [start_abc.Index_of_threads] = 1;
}

int main()
{


start_abc.initiate(100)


while (true)//normally without the libary it will spawn infinite threads to take a lots resources on the machine
{

start_abc.booker();

abc[start_abc.Index_of_threads]=std::thread(hello_world);
}


}

althread's People

Contributors

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