-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample3.pl
executable file
·71 lines (61 loc) · 1.57 KB
/
sample3.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/perl
use strict;
require 'grm.pl';
my ($host, $port, $sts1, $sts2, $i, $rec);
#
if (@ARGV != 2){
printf("usage: $0 host port\n");
exit 1;
}
($host, $port) = @ARGV;
#
for ($i = 0; $i < 100; $i++){
$sts1 = &grm_lock($host, $port, "p3", "r1.txt", "x", "poipoi");
if ($sts1 ne "OK"){
print "lock error p3, r1.txt\n";
exit 1;
}
$sts2 = &grm_lock($host, $port, "p3", "r2.txt", "x", "poipoi");
while ($sts2 eq "DEADLOCK"){
print "p3 DEADLOCK retry\n";
$sts1 = &grm_unlock($host, $port, "p3", "r1.txt", "poipoi");
if ($sts1 ne "OK"){
print "unlock error p3, r1.txt\n";
exit 1;
}
$sts1 = &grm_lock($host, $port, "p3", "r1.txt", "x", "poipoi");
if ($sts1 ne "OK"){
print "lock error p3, r1.txt\n";
exit 1;
}
$sts2 = &grm_lock($host, $port, "p3", "r2.txt", "x", "poipoi");
}
if ($sts2 ne "OK"){
print "lock error p3, r2.txt\n";
exit 1;
}
open(FD1, "<r1.txt");
$rec = <FD1>;
close(FD1);
$rec++;
open(FD1, ">r1.txt");
print FD1 $rec;
close(FD1);
open(FD2, "<r2.txt");
$rec = <FD2>;
close(FD2);
$rec++;
open(FD2, ">r2.txt");
print FD2 $rec;
close(FD2);
$sts1 = &grm_unlock($host, $port, "p3", "r1.txt", "poipoi");
if ($sts1 ne "OK"){
print "unlock error p3, r1.txt\n";
exit 1;
}
$sts2 = &grm_unlock($host, $port, "p3", "r2.txt", "poipoi");
if ($sts2 ne "OK"){
print "unlock error p3, r2.txt\n";
exit 1;
}
}