Ticket #3582: boost_file_lock_test.cpp

File boost_file_lock_test.cpp, 536 bytes (added by joseph@…, 13 years ago)

test case

Line 
1#include <iostream>
2#include <fstream>
3#include <unistd.h>
4
5#include <boost/interprocess/sync/file_lock.hpp>
6
7using namespace std;
8using namespace boost::interprocess;
9
10int main(int argc, char *argv[]) {
11 file_lock flock("lock");
12
13 if (flock.try_lock()) cout << "Acquired lock" << endl;
14 else {
15 cout << "Could not acquire lock" << endl;
16 return 1;
17 }
18
19 ifstream file("lock");
20
21 // If you comment out the next line the lock stays active during the sleep.
22 file.close(); // also closes lock
23
24 sleep(30);
25
26 return 0;
27}