Skip to content

Instantly share code, notes, and snippets.

@jamboree
Created September 18, 2014 07:49
Show Gist options
  • Save jamboree/ea6e351aa0f4e59ef8ea to your computer and use it in GitHub Desktop.
Save jamboree/ea6e351aa0f4e59ef8ea to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
int main(int argc, char** argv)
{
namespace ipc = boost::interprocess;
std::fclose(std::fopen("lock", "w"));
ipc::file_lock flock("lock");
ipc::scoped_lock<ipc::file_lock> lock(flock, ipc::defer_lock);
if (lock.try_lock())
std::cout << "ok\n";
else
std::cout << "fail\n";
std::system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment