<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://panoptic.com/mediawiki/aolserver/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hcd000</id>
	<title>AOLserver Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://panoptic.com/mediawiki/aolserver/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hcd000"/>
	<link rel="alternate" type="text/html" href="https://panoptic.com/wiki/aolserver/Special:Contributions/Hcd000"/>
	<updated>2026-04-17T11:09:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://panoptic.com/mediawiki/aolserver/index.php?title=Ns_critsec&amp;diff=5159</id>
		<title>Ns critsec</title>
		<link rel="alternate" type="text/html" href="https://panoptic.com/mediawiki/aolserver/index.php?title=Ns_critsec&amp;diff=5159"/>
		<updated>2008-08-29T15:39:55Z</updated>

		<summary type="html">&lt;p&gt;Hcd000: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Man page: http://aolserver.com/docs/tcl/ns_critsec.html&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''NAME'''&lt;br /&gt;
&lt;br /&gt;
: ns_critsec - Operate on critical section objects&lt;br /&gt;
&lt;br /&gt;
'''SYNOPSIS'''&lt;br /&gt;
&lt;br /&gt;
: '''ns_critsec''' ''option ?arg arg ...?''&lt;br /&gt;
&lt;br /&gt;
'''DESCRIPTION'''&lt;br /&gt;
&lt;br /&gt;
: This command provides a mechanism to manipulate critical section objects.  The legal ''option''s (which may be abbreviated) are:&lt;br /&gt;
* '''ns_critsec create'''&lt;br /&gt;
&lt;br /&gt;
: Initializes a new critical section object and returns a handle to it.&lt;br /&gt;
* '''ns_critsec destroy''' ''object''&lt;br /&gt;
&lt;br /&gt;
: Destroys the critical section object and frees any resources it was using.&lt;br /&gt;
* '''ns_critsec enter''' ''object''&lt;br /&gt;
&lt;br /&gt;
: Enters the critical section.  The thread will block if another thread is already in the critical section.&lt;br /&gt;
* '''ns_critsec leave''' ''object''&lt;br /&gt;
&lt;br /&gt;
: Leaves the critical section.  When the thread leaves the critical section as many times as it has entered, a notification will be sent to other threads that are waiting on the critical section.&lt;br /&gt;
&lt;br /&gt;
'''EXAMPLES'''&lt;br /&gt;
&lt;br /&gt;
Is this the right way to use this command? The example is contrived, but I wanted to call ns_critsec multiple times.&lt;br /&gt;
&lt;br /&gt;
    # If a thread is executing any of these procs, no other&lt;br /&gt;
    # thread can execute any of these procs until the first&lt;br /&gt;
    # thread has completely finished.&lt;br /&gt;
    &lt;br /&gt;
    nsv_set . special_file_critsec [ns_critsec create]&lt;br /&gt;
    &lt;br /&gt;
    proc write_special_file {data} {&lt;br /&gt;
        set critsec [nsv_get . special_file_critsec]&lt;br /&gt;
        ns_critsec enter $critsec&lt;br /&gt;
        set handle [open special_file w]&lt;br /&gt;
        puts $handle $data&lt;br /&gt;
        close $handle&lt;br /&gt;
        ns_critsec leave $critsec&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    proc read_special_file {} {&lt;br /&gt;
        set critsec [nsv_get . special_file_critsec]&lt;br /&gt;
        ns_critsec enter $critsec&lt;br /&gt;
        set handle [open special_file r]&lt;br /&gt;
        set result [read $handle]&lt;br /&gt;
        close $handle&lt;br /&gt;
        ns_critsec leave $critsec&lt;br /&gt;
        return $result&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    proc change_special_file {data} {&lt;br /&gt;
        set critsec [nsv_get . special_file_critsec]&lt;br /&gt;
        ns_critsec enter $critsec&lt;br /&gt;
        set result [read_special_file]&lt;br /&gt;
        write_special_file $data&lt;br /&gt;
        ns_critsec leave $critsec&lt;br /&gt;
        return $result&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
'''SEE ALSO'''&lt;br /&gt;
&lt;br /&gt;
: [[ns_cond]], [[ns_event]], [[ns_mutex]], [[ns_thread]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
[[Category Documentation]] - [[Category Core Tcl API]]&lt;/div&gt;</summary>
		<author><name>Hcd000</name></author>
		
	</entry>
</feed>