2 a simple demonsration of a scaling problem in byte range locks on solaris
4 try this as 'locker 800 1' and compare to 'locker 800 0'
6 tridge@samba.org, July 2002
18 static int brlock(int fd, off_t offset, int rw_type, int lck_type)
24 fl.l_whence = SEEK_SET;
29 ret = fcntl(fd,lck_type,&fl);
32 printf("brlock failed offset=%d rw_type=%d lck_type=%d : %s\n",
33 (int)offset, rw_type, lck_type, strerror(errno));
38 static void slave(int fd, int nlocks)
41 for (i=1; i<nlocks+1; i++) {
42 brlock(fd, i, F_RDLCK, F_SETLKW);
43 usleep(1); /* essentially just a yield() */
46 /* this last lock will block until the master unlocks it */
47 brlock(fd, 0, F_WRLCK, F_SETLKW);
48 brlock(fd, 0, F_UNLCK, F_SETLKW);
51 int main(int argc, char *argv[])
55 const char *fname = "locker.dat";
59 printf("Usage: locker <nproc> <nlocks>\n");
63 nproc = atoi(argv[1]);
64 nlocks = atoi(argv[2]);
67 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0600);
73 /* set the master lock - this stops the children exiting */
74 brlock(fd, 0, F_WRLCK, F_SETLKW);
76 for (i=0;i<nproc;i++) {
88 printf("hit enter to continue\n");
91 printf("unlocking ....\n");
92 brlock(fd, 0, F_UNLCK, F_SETLKW);
94 while (waitpid(0, NULL, 0) > 0 || errno != ECHILD) /* noop */ ;