source: testjes/testlock.cpp @ 10

Last change on this file since 10 was 10, checked in by willem, 11 years ago

willem

File size: 714 bytes
Line 
1#include <iostream>
2#include <unistd.h>
3#include <fcntl.h>
4#include <stdio.h>
5
6int main()
7{
8  int f;
9  std::string fname = "/tmp/testdb_flat";
10  f = open(fname.c_str(),O_CREAT|O_RDWR,0600);
11  if (f < 0)
12  {
13    perror("open error:");
14    return 1;
15  }
16  int rc;
17  struct flock lock;
18  lock.l_type = F_RDLCK|F_WRLCK;
19  lock.l_whence = SEEK_SET;
20  lock.l_start  = 0;
21  lock.l_len    = 0;
22
23  std::cout << "getting lock ... \n";
24  rc = fcntl(f,F_SETLKW,&lock);
25
26  std::cout << " got it, sleeping\n";
27  sleep(15);
28  std::cout << " releasing lock\n";
29  lock.l_type = F_UNLCK;
30  lock.l_whence = SEEK_SET;
31  lock.l_start  = 0;
32  lock.l_len    = 0;
33  rc  = fcntl(f,F_SETLKW,&lock);
34
35  std::cout << "done\n";
36
37  return 0;
38}
Note: See TracBrowser for help on using the repository browser.