Px - Single header C++ Libraries for Thread Scheduling, Rendering, and so on...

Overview

px

'PpluX' Single header C++(11/14) Libraries

Name Code Description
px_sched px_sched.h Task oriented scheduler. See more
px_render px_render.h Multithreaded, Command Based render backend. See more (WIP)
px_render_gltf px_render_gltf.h Module for px_render to load GLTF (thanks to tinygltf) example
px_render_imgui px_render_imgui.h Dear Imgui render backend for px_render
px_mem px_mem.h Safe memory management constructs (safer unique_ptr with futher restrictions, and avoiding new/delete completely)
Comments
  • Possible Makefile error on Linux (and fix)

    Possible Makefile error on Linux (and fix)

    Hi. I've cloned the repository and tried compiling it with:

    .../.../px/examples$ make
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example1 -lpthread -lpthread px_sched_example1.cpp
    /tmp/cce6YjPP.o: In function `std::thread::thread<void (&)(px_sched::Scheduler*, px_sched::Scheduler::Worker*), px_sched::Scheduler*, px_sched::Scheduler::Worker*>(void (&)(px_sched::Scheduler*, px_sched::Scheduler::Worker*), px_sched::Scheduler*&&, px_sched::Scheduler::Worker*&&)':
    /usr/include/c++/5/thread:137: undefined reference to `pthread_create'
    collect2: error: ld returned 1 exit status
    Makefile:42: recipe for target 'px_sched_example1' failed
    make: *** [px_sched_example1] Error 1
    

    Then, based on these links link1 link2 (that seem to contradict each other :smiley: ), I thought that -lpthread must be put after the source files, whereas -pthread only can be used before the source files.

    I've tried the latter and simply replaced -lpthread with -pthread in the Makefile. I don't know if this is the right solution, but it worked:

    .../.../px/examples$ make clean
    rm -f px_sched_example1 px_sched_example2 px_sched_example3 px_sched_example4 px_sched_example5 px_sched_example6 px_sched_example7
    .../...//px/examples$ make
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example1 -pthread px_sched_example1.cpp
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example2 -pthread px_sched_example2.cpp
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example3 -pthread px_sched_example3.cpp
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example4 -pthread px_sched_example4.cpp
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example5 -pthread px_sched_example5.cpp
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example6 -pthread px_sched_example6.cpp
    g++ -std=c++11 -pedantic -g -O2 -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wdouble-promotion -Werror -Wextra -Wformat=2 -Winit-self -Wmissing-include-dirs -Wno-unused -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef  -o px_sched_example7 -pthread px_sched_example7.cpp
    

    Hope it helps other Linux users having the same problems :smile: .

    opened by Flix01 5
  • Compile error

    Compile error

    I cant compile with the .bat. I am using 2014 VS with C++14 support 'px_sched::ObjectPool<px_sched::Scheduler::Task>::D::state': is not a type name, static, or enumerator

    opened by PabloPicose 4
  • px_render_gltf. Out of bounds error because of sampler

    px_render_gltf. Out of bounds error because of sampler

    Test model: test_model.zip

    For myself I just hardcoded

    	new_texture.info.magnification_filter = SamplerFiltering::Linear;
            new_texture.info.minification_filter  = SamplerFiltering::LinearMipmapLinear;
            new_texture.info.wrapping[0] = SamplerWrapping::Repeat;
            new_texture.info.wrapping[1] = SamplerWrapping::Repeat;
            new_texture.info.wrapping[2] = SamplerWrapping::Repeat;
    

    ...and everything works. I have an assumption that the model has no legal samplers

    So problem line is https://github.com/pplux/px/blob/76a703379e96916210f14a4eeac60ff1d89c7cce/px_render_gltf.h#L303

    opened by NukeBird 3
  • Fix compilation on Linux

    Fix compilation on Linux

    make -C examples fails on Arch Linux with a lengthty:

    g++ -std=c++14 -fpermissive -D linux -g -O2 -I . -o px_render_example_imgui px_render_example_imgui.cpp -lpthread -ldl -lX11
    In file included from common/../deps/sokol_app.h:5487,
                     from common/render_common.h:35,
                     from px_render_example_imgui.cpp:1:
    common/../../px_render.h:153:7: error: expected identifier before numeric constant
      153 |       None = 0,
          |       ^~~~
    common/../../px_render.h:153:7: error: expected ‘}’ before numeric constant
    In file included from common/render_common.h:40,
                     from px_render_example_imgui.cpp:1:
    common/../../px_render.h:152:15: note: to match this ‘{’
      152 |     enum Enum {
          |               ^
    In file included from common/../deps/sokol_app.h:5487,
                     from common/render_common.h:35,
                     from px_render_example_imgui.cpp:1:
    common/../../px_render.h:153:7: error: expected unqualified-id before numeric constant
      153 |       None = 0,
          |       ^~~~
    common/../../px_render.h:240:7: error: expected identifier before numeric constant
      240 |       Always,
          |       ^~~~~~
    common/../../px_render.h:240:7: error: expected ‘}’ before numeric constant
    
    <CUT>
    
    opened by krant 1
  • [OT] Possible use of Tinythreadpp to replace C++11

    [OT] Possible use of Tinythreadpp to replace C++11

    [I'm closing this soon because it's not a real issue]

    I remember that some years ago I liked this library a lot: [tinythreadpp] [API reference here].

    From your docs, it seems that px_sched.h is:

    • Portable, written in C++11 with no dependency
    • C++11 only used for thread, mutex, and condition variable no STL container is used

    whereas px_render.h is more complex (needs C++11/C++14).

    I'm wondering if px_sched.h can be compiled without C++11, just using tinythreadpp.

    AFAIR, the API is very similar (except a few missing constructor overloads in the thread class).

    However, this post is just a useless experiment: nowadays most compilers support C++11. Maybe this is just something for people trying to minimize file size (I don't think tinythreadpp uses STL, but I have to check).

    So basically I'm going to close this now, leaving this post just as a suggestion for the few users that can be interested in removing the C++11 dependency from px_sched.h.

    Sorry for polluting the Issue Section.

    opened by Flix01 1
  • Entry point is not defined in the examples

    Entry point is not defined in the examples

    Entry point is not defined in the examples, how can I execute it? I added the default "main" entry, and then call to sokol_main(int argc, char **argv) with the default parameters. Is there a preprocesor or something to determine the entry in your API? Thanks, I am waiting for a reasonable documentation to how to start or something

    opened by TesterPointer 1
  • Backend resource cleanup bug

    Backend resource cleanup bug

    Hi, I found a little yet annoying bug which causes severe issues after calling destroy() with px_render::Pipeline and subsequent call of createPipeline. There's one line missing in DestroyBackEndResource(), right after you call glDeleteProgram: GLCHECK(glDeleteProgram(b->pipelines[pos].program)); b->pipelines[pos].program = 0; // <---- this one is required

    Without this you'll get a lot of OpenGL errors by using deleted and reused Pipeline (since createPipeline reuses previously deleted Pipeline), because this check in ChangePipeline will always fail to execute the inner code in the if() block: if (pi.second->program == 0) {

    opened by mrduda 0
  • IMGUI reference imp, switch to RGB32, and make the shader use RGB instead of RRR

    IMGUI reference imp, switch to RGB32, and make the shader use RGB instead of RRR

    Any texture exposed from px_render, would be in B&W due to the fact that the shader only uses the first channel (for text is fine, but... nothing else)

    bug 
    opened by pplux 0
  • Allow for waiting threads to do jobs

    Allow for waiting threads to do jobs

    Pseudo code:

            px_sched::Sync sync;
            for(int i = 0; i < 100; ++i) {
                scheduler.runTask([&](){
                    // Heavy task
                    }, &sync);
            }
            scheduler.waitFor(sync);
    

    Here the calling thread that creates the task will suspend waiting for the tasks to be finished before carrying on. This requires the pool of threads to be bigger than the actual core count to allow some threads wait for others and still have enough threads to keep using all cpus. One possible solution could be for the thread that waits on a sync object to start doing tasks from the list of tasks related to that sync object.

    The idea is that if the thread needs to wait for a task to be finished it can go on and start working on that lists of tasks itself instead of waiting.

    enhancement 
    opened by pplux 1
Owner
PpluX
PpluX
Thread-pool - Thread pool implementation using c++11 threads

Table of Contents Introduction Build instructions Thread pool Queue Submit function Thread worker Usage example Use case#1 Use case#2 Use case#3 Futur

Mariano Trebino 655 Dec 27, 2022
Thread-pool-cpp - High performance C++11 thread pool

thread-pool-cpp It is highly scalable and fast. It is header only. No external dependencies, only standard library needed. It implements both work-ste

Andrey Kubarkov 542 Dec 17, 2022
Sqrt OS is a simulation of an OS scheduler and memory manager using different scheduling algorithms including Highest Priority First (non-preemptive), Shortest Remaining Time Next, and Round Robin

A CPU scheduler determines an order for the execution of its scheduled processes; it decides which process will run according to a certain data structure that keeps track of the processes in the system and their status.

null 10 Sep 7, 2022
OOX: Out-of-Order Executor library. Yet another approach to efficient and scalable tasking API and task scheduling.

OOX Out-of-Order Executor library. Yet another approach to efficient and scalable tasking API and task scheduling. Try it Requirements: Install cmake,

Intel Corporation 18 Oct 25, 2022
Operating system project - implementing scheduling algorithms and some system calls for XV6 OS

About XV6 xv6 is a modern reimplementation of Sixth Edition Unix in ANSI C for multiprocessor x86 and RISC-V systems. It was created for pedagogical p

Amirhossein Rajabpour 22 Dec 22, 2022
Bistro: A fast, flexible toolkit for scheduling and running distributed tasks

Bistro is a flexible distributed scheduler, a high-performance framework supporting multiple paradigms while retaining ease of configuration, management, and monitoring.

Facebook 1k Dec 19, 2022
A task scheduling framework designed for the needs of game developers.

Intel Games Task Scheduler (GTS) To the documentation. Introduction GTS is a C++ task scheduling framework for multi-processor platforms. It is design

null 424 Jan 3, 2023
Scheduler - Modern C++ Scheduling Library

Scheduler Modern C++ Header-Only Scheduling Library. Tasks run in thread pool. Requires C++11 and ctpl_stl.h in the path. Inspired by the Rufus-Schedu

Spencer Bosma 232 Dec 21, 2022
Fork of rpmalloc to be used with single thread applications and old C compilers

srpmalloc - Small rpmalloc This is a fork of rpmalloc, with the intent to be used in single threaded applications only, with old C99 compilers, and in

Eduardo Bart 8 Oct 28, 2022
A competitive programming helper tool, which packages included libraries into a single file, suitable for online judges.

cpack Cpack is a competitive programming helper tool, which packages the main source file along with included libraries into a single file, suitable f

PetarMihalj 11 Apr 22, 2022
EOSP ThreadPool is a header-only templated thread pool writtent in c++17.

EOSP Threadpool Description EOSP ThreadPool is a header-only templated thread pool writtent in c++17. It is designed to be easy to use while being abl

null 1 Apr 22, 2022
A bounded single-producer single-consumer wait-free and lock-free queue written in C++11

SPSCQueue.h A single producer single consumer wait-free and lock-free fixed size queue written in C++11. Example SPSCQueue<int> q(2); auto t = std::th

Erik Rigtorp 576 Dec 27, 2022
A fast single-producer, single-consumer lock-free queue for C++

A single-producer, single-consumer lock-free queue for C++ This mini-repository has my very own implementation of a lock-free queue (that I designed f

Cameron 2.9k Jan 5, 2023
Simple and fast C library implementing a thread-safe API to manage hash-tables, linked lists, lock-free ring buffers and queues

libhl C library implementing a set of APIs to efficiently manage some basic data structures such as : hashtables, linked lists, queues, trees, ringbuf

Andrea Guzzo 392 Dec 3, 2022
C++20's jthread for C++11 and later in a single-file header-only library

jthread lite: C++20's jthread for C++11 and later A work in its infancy. Suggested by Peter Featherstone. Contents Example usage In a nutshell License

Martin Moene 50 Dec 8, 2022
High Performance Linux C++ Network Programming Framework based on IO Multiplexing and Thread Pool

Kingpin is a C++ network programming framework based on TCP/IP + epoll + pthread, aims to implement a library for the high concurrent servers and clie

null 23 Oct 19, 2022
ThreadPool - A fastest, exception-safety and pure C++17 thread pool.

Warnings Since commit 468129863ec65c0b4ede02e8581bea682351a6d2, I move ThreadPool to C++17. (To use std::apply.) In addition, the rule of passing para

Han-Kuan Chen 124 Dec 28, 2022
CTPL - Modern and efficient C++ Thread Pool Library

CTPL Modern and efficient C++ Thread Pool Library A thread pool is a programming pattern for parallel execution of jobs, http://en.wikipedia.org/wiki/

null 1.1k Dec 22, 2022
Single header asymmetric stackful cross-platform coroutine library in pure C.

minicoro Minicoro is single-file library for using asymmetric coroutines in C. The API is inspired by Lua coroutines but with C use in mind. The proje

Eduardo Bart 405 Dec 29, 2022