1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# TEST mut002 8# TEST Two-process mutex test. 9# 10# TEST Allocate and lock a self-blocking mutex. Start another process. 11# TEST Try to lock the mutex again -- it will block. 12# TEST Unlock the mutex from the other process, and the blocked 13# TEST lock should be obtained. Clean up. 14# TEST Do another test with a "-process-only" mutex. The second 15# TEST process should not be able to unlock the mutex. 16 17proc mut002 { } { 18 source ./include.tcl 19 20 puts "Mut002: Two process mutex test." 21 22 # Open an env. 23 set env [berkdb_env -create -home $testdir] 24 25 puts "\tMut002.a: Allocate and lock a mutex." 26 set mutex [$env mutex -self_block] 27 error_check_good obtained_lock [$env mutex_lock $mutex] 0 28 29 # Start a second process. 30 puts "\tMut002.b: Start another process." 31 set p2 [exec $tclsh_path $test_path/wrap.tcl mut002script.tcl\ 32 $testdir/mut002.log $testdir $mutex &] 33 34 # Try to lock the mutex again. This will hang until the second 35 # process unlocks it. 36 $env mutex_lock $mutex 37 38 watch_procs $p2 1 20 39 40 # Clean up, and check the log file from process 2. 41 error_check_good mutex_unlock [$env mutex_unlock $mutex] 0 42 error_check_good env_close [$env close] 0 43 44 # We expect the log file to be empty. If there are any 45 # messages, report them as failures. 46 set fd [open $testdir/mut002.log r] 47 while { [gets $fd line] >= 0 } { 48 puts "FAIL: unexpected output in log file mut002: $line" 49 } 50 close $fd 51} 52 53