1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1996-2002
4
# Sleepycat Software. All rights reserved.
10
# TEST Test basic mutex synchronization
14
puts "Mutex002: Basic synchronization"
18
# Fork off child before we open any files.
19
set f1 [open |$tclsh_path r+]
20
puts $f1 "source $test_path/test.tcl"
23
# Open the environment and the mutex locally
24
puts "\tMutex002.a: Open local and remote env"
25
set local_env [berkdb_env -create -mode 0644 -lock -home $testdir]
26
error_check_good env_open [is_valid_env $local_env] TRUE
28
set local_mutex [$local_env mutex 0644 $nlocks]
30
mutex_init [is_valid_mutex $local_mutex $local_env] TRUE
32
# Open the environment and the mutex remotely
33
set remote_env [send_cmd $f1 "berkdb_env -lock -home $testdir"]
34
error_check_good remote:env_open [is_valid_env $remote_env] TRUE
36
set remote_mutex [send_cmd $f1 "$remote_env mutex 0644 $nlocks"]
38
mutex_init [is_valid_mutex $remote_mutex $remote_env] TRUE
40
# Do a get here, then set the value to be pid.
41
# On the remote side fire off a get and getval.
42
puts "\tMutex002.b: Local and remote get/set"
43
set r [$local_mutex get 1]
44
error_check_good lock_get $r 0
46
set r [$local_mutex setval 1 [pid]]
47
error_check_good lock_get $r 0
49
# Now have the remote side request the lock and check its
50
# value. Then wait 5 seconds, release the mutex and see
51
# what the remote side returned.
52
send_timed_cmd $f1 1 "$remote_mutex get 1"
53
send_timed_cmd $f1 1 "set ret \[$remote_mutex getval 1\]"
55
# Now sleep before resetting and releasing lock
57
set newv [expr [pid] - 1]
58
set r [$local_mutex setval 1 $newv]
59
error_check_good mutex_setval $r 0
61
set r [$local_mutex release 1]
62
error_check_good mutex_release $r 0
64
# Now get the result from the other script
66
set result [rcv_result $f1]
67
error_check_good lock_get:remote_time [expr $result > 4] 1
70
set result [rcv_result $f1]
73
set result [send_cmd $f1 "puts \$ret"]
74
error_check_good lock_get:remote_getval $result $newv
76
# Close down the remote
77
puts "\tMutex002.c: Close remote"
78
set ret [send_cmd $f1 "$remote_mutex close" 5]
79
# Not sure why we need this, but we do... an extra blank line
80
# someone gets output somewhere
82
error_check_good remote:mutex_close $ret 0
84
set ret [send_cmd $f1 "$remote_env close"]
85
error_check_good remote:env_close $ret 0
87
catch { close $f1 } result
89
set ret [$local_mutex close]
90
error_check_good local:mutex_close $ret 0
92
set ret [$local_env close]
93
error_check_good local:env_close $ret 0