Skip to content

stryku/file_mutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

file_mutex

A boost::interprocess::file_mutex class proposal. Class' purpose is to synchronize file access from multiple processes. It has sharable and exclusive locking capabilities and can be used with scoped_lock and sharable_lock classes.

Example usage:

#include <boost/interprocess/sync/file_mutex.hpp>

#include <iostream>
#include <mutex>

int main(int argc, char* argv[])
{
    const auto path = "test_file.txt";
    std::ofstream file(path, std::ios::app);
    boost::interprocess::file_mutex file_mutex(path);

    std::lock_guard<boost::interprocess::file_mutex> lock(file_mutex);

    for (auto i = 0u; i < 10; ++i)
    {
        std::cout << "Writing " << i << " " << argv[1] << "\n";
        file << argv[1] << "\n";
        std::this_thread::sleep_for(std::chrono::seconds{ 1 });
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages