Skip to content

mguludag/shared_memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

shared_memory

a simple thread safe shared_memory concept

Usage

#include <thread>
#include "shared_memory.hpp"


int main()
{
    using sm_dq_int = stdx::shared_memory<int>; // deque<int> shared memory
    using sm_vec_int = stdx::shared_memory<int, std::vector>; // vector<int> shared memory

    std::thread t1([&]{
        for(int i=0; i<10000; ++i){
            sm_vec_int::push_back(i);
        }});

    std::thread t2([&]{
        for(int i=10000; i<20000; ++i){
            sm_vec_int::push_back(i);
        }});

    std::thread t4([&]{
        for(auto &i : sm_vec_int::data()){
            std::cout<<i<<" ";
        }});

    t1.join();
    t2.join();
    t4.join();

}

Releases

No releases published

Packages

No packages published

Languages