Created
September 18, 2014 07:49
-
-
Save jamboree/ea6e351aa0f4e59ef8ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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