Index: openacs-4/packages/xotcl-core/tcl/40-thread-mod-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/40-thread-mod-procs.tcl,v diff -u -N -r1.3 -r1.3.2.1 --- openacs-4/packages/xotcl-core/tcl/40-thread-mod-procs.tcl 14 Jul 2006 01:22:11 -0000 1.3 +++ openacs-4/packages/xotcl-core/tcl/40-thread-mod-procs.tcl 1 Aug 2007 21:39:32 -0000 1.3.2.1 @@ -12,7 +12,7 @@ When an instance of THREAD is created (e.g. t1), an init-command is provided. e.g.:
-    THREAD create t1 {
+    ::xotcl::THREAD create t1 {
       Class Counter -parameter {{value 1}}
       Counter instproc ++ {} {my incr value}
       Counter c1
@@ -52,7 +52,7 @@
    creates a Proxy for an object c1 in thread t1.
    After this, c1 can be used like an local object.
   
-    THREAD::Proxy c1 -attach t1
+    ::xotcl::THREAD::Proxy c1 -attach t1
     set x [c1 ++]
   
The Proxy forwards all commands to the @@ -85,9 +85,9 @@ ::xotcl::Object setExitHandler { #my log "EXITHANDLER of request thread [pid]" - if {[catch {Proxy detachAll} m]} { - #my log "EXITHANDLER error in detachAll $m" - } + #if {[catch {::xotcl::THREAD::Proxy detachAll} m]} { + # #my log "EXITHANDLER error in detachAll $m" + #} } ::Serializer exportObjects { @@ -102,7 +102,7 @@ # -parameter {{persistent 0}} Class create ::xotcl::THREAD \ - -parameter {{persistent 0}} + -parameter {{persistent 0} {lightweight 0}} #Class create ::xotcl::THREAD \ # -parameter {{persistent 0}} @@ -117,8 +117,20 @@ } ::xotcl::THREAD instproc init cmd { - my instvar initcmd - set initcmd { + my instvar initcmd + if {![ns_ictl epoch]} { + #ns_log notice "--THREAD init [self] no epoch" + + # We are during initialization. For some unknown reasons, XOTcl + # is not available in newly created threads, so we have to care for it. + # We need only a partial initialization, to allow the exit handler + # to be defined. + set initcmd { + package req XOTcl + namespace import -force ::xotcl::* + } + } + append initcmd { ::xotcl::Object setExitHandler { #my log "EXITHANDLER of slave thread SELF [pid]" } @@ -161,7 +173,7 @@ my log "thread terminated" nsv_unset [self class] [self] thread::mutex destroy [my set mutex] - ns_log notice "mutex [my set mutex] destroyed" + my log "+++ mutex [my set mutex] destroyed" } } next @@ -186,14 +198,31 @@ #my check_blueprint #my log "after lock" if {![nsv_exists [self class] [self]]} { - set tid [::thread::create] + if {[my lightweight]} { + my log "CREATE lightweight thread" + set tid [::thread::create -thin] + } else { + set tid [::thread::create] + } nsv_set [self class] [self] $tid if {[my persistent]} { - my log "created new persistent [self class] as $tid pid=[pid]" + my log "--created new persistent [self class] as $tid pid=[pid]" } else { - my log "created new [self class] as $tid pid=[pid]" + my log "--created new [self class] as $tid pid=[pid]" } - ::thread::send $tid [my set initcmd] + #my log "--THREAD DO send [self] epoch = [ns_ictl epoch]" + if {[my lightweight]} { + } elseif {![ns_ictl epoch]} { + #ns_log notice "--THREAD send [self] no epoch" + # We are during initialization. For some unknown reasons, XOTcl + # is not available in newly created threads, so we have to care + # for full initialization, including xotcl blueprint. + _ns_savenamespaces + set initcmd [ns_ictl get] + } + append initcmd [my set initcmd] + #ns_log notice "INIT $initcmd" + ::thread::send $tid $initcmd } else { set tid [nsv_get [self class] [self]] } @@ -223,7 +252,7 @@ # create a sample persistent thread that can be acessed # via request threads -#THREAD create t0 { +#::xotcl::THREAD create t0 { # Class Counter -parameter {{value 1}} # Counter instproc ++ {} {my incr value} #