xref: /openbsd-src/gnu/usr.bin/perl/cpan/Memoize/t/st_concurrency (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1*f2a19305Safresh1#!/bin/sh
2*f2a19305Safresh1
3*f2a19305Safresh1# running this script intermittently yields
4*f2a19305Safresh1#
5*f2a19305Safresh1#     Magic number checking on storable file failed at ...
6*f2a19305Safresh1#
7*f2a19305Safresh1# but it is difficult to trigger this error 100% reliably
8*f2a19305Safresh1# as would be needed to turn this script into an actual test
9*f2a19305Safresh1
10*f2a19305Safresh1perl -I. -x t/st_concurrency st_shared &
11*f2a19305Safresh1perl -I. -x t/st_concurrency st_shared &
12*f2a19305Safresh1perl -I. -x t/st_concurrency st_shared &
13*f2a19305Safresh1perl -I. -x t/st_concurrency st_shared &
14*f2a19305Safresh1wait && exec rm st_shared
15*f2a19305Safresh1
16*f2a19305Safresh1#!perl
17*f2a19305Safresh1use strict; use warnings;
18*f2a19305Safresh1
19*f2a19305Safresh1use Memoize::Storable;
20*f2a19305Safresh1use Fcntl 'LOCK_EX';
21*f2a19305Safresh1
22*f2a19305Safresh1sub rand32 () { int rand 1<<32 }
23*f2a19305Safresh1
24*f2a19305Safresh1# the script locks itself to increase the likelihood of the error:
25*f2a19305Safresh1# after releasing the lock, the first process writes to the file
26*f2a19305Safresh1# just as another process acquires the lock and starts to read it
27*f2a19305Safresh1# (but this still does not trigger the error reliably)
28*f2a19305Safresh1
29*f2a19305Safresh1open my $fh, $0 or die $!;
30*f2a19305Safresh1flock $fh, LOCK_EX or die $!;
31*f2a19305Safresh1
32*f2a19305Safresh1tie my %cache => 'Memoize::Storable', $ARGV[0];
33*f2a19305Safresh1$cache{(rand32)} = rand32;
34*f2a19305Safresh1
35*f2a19305Safresh1close $fh;
36*f2a19305Safresh1# vim: ft=perl
37