ns_critsec - Operate on critical section objects
TABLE OF CONTENTS
SYNOPSIS
DESCRIPTION
COMMANDS
EXAMPLES
KEYWORDS
|
This command provides a mechanism to manipulate critical section objects.
Is this the right way to use this command? The example is contrived, but I wanted to call ns_critsec multiple times.
# If a thread is executing any of these procs, no other
# thread can execute any of these procs until the first
# thread has completely finished.
nsv_set . special_file_critsec [ns_critsec create]
proc write_special_file {data} {
set critsec [nsv_get . special_file_critsec]
ns_critsec enter $critsec
set handle [open special_file w]
puts $handle $data
close $handle
ns_critsec leave $critsec
}
proc read_special_file {} {
set critsec [nsv_get . special_file_critsec]
ns_critsec enter $critsec
set handle [open special_file r]
set result [read $handle]
close $handle
ns_critsec leave $critsec
return $result
}
proc change_special_file {data} {
set critsec [nsv_get . special_file_critsec]
ns_critsec enter $critsec
set result [read_special_file]
write_special_file $data
ns_critsec leave $critsec
return $result
}
|