View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] setExitHandler & threads

From: Scott Gargash <scottg_at_atc.creative.com>
Date: Thu, 10 Aug 2006 20:49:54 -0600

I've run into an interaction with threads and the XOTcl exit handler that I don't understand.

I create a thread from within an object, and release that thread in the object's destructor. If I
destroy the object directly, everything's fine, but if I destroy the object through "Object
setExitHandler", I get an error. Am I treading into undefined behavior? Is there well-defined way
to shut down multiple threads?

      Scott

Here's some sample code:

package require XOTcl
package require Thread

namespace import {xotcl::*}
Class A
A instproc init {} {
  my set tid [thread::create [subst -nocommands {
    set ::auto_path [list $::auto_path]
    package require XOTcl
    namespace import {xotcl::*}
    Object b
    thread::wait
  }]]
}

A instproc destroy {args} {
  thread::send [my set tid] {b destroy}
  thread::release [my set tid]
  next
}

A a
if {0} {
  # This gives an error
  xotcl::Object setExitHandler {a destroy}
} else {
  # this works
  a destroy
}

exit