I just took a quick look at the java.awt.EventQueue class where the dispatch
thread is managed, and I could see no obvious place you could hook in your
own calling code, which you'd need to wrap it with a (binding ...) form.

If you really want to hack the system, look at the code in core.clj for
binding.  It looks like you could force a call into Var.pushThreadBinding()
in the dispatch thread.  However, doing that is risky and is definately
subverting the system.  Don't complain if it blows up in your face.

I would suggest you either implment it as a global Atom, or perhaps go down
the the Java level and use a ThreadLocal.

On Wed, Feb 11, 2009 at 10:30 PM, Chas Emerick <cemer...@snowtide.com>wrote:

>
> def doesn't create a thread-local binding, it creates a var within a
> particular namespace -- the binding form is what established the
> thread-local binding.  So, when used on the AWT/Swing thread,
>
> (binding [*my_environment* (new_environment)]
>    ...)
>
> will execute the body of the binding form with the *my_environment*
> var bound to the value of (new_environment).
>
> - Chas
>
> On Feb 11, 2009, at 8:40 PM, CuppoJava wrote:
>
> >
> > Hi,
> > I just wrote a library that creates an un-initialized global variable,
> > and requires the user to create his own thread-local binding in order
> > to run it.
> >
> > eg.
> > (def *my_environment*)
> > ...
> >
> > and the user would use it like so:
> > (binding [*my_environment* (new_environment)]
> >  (start_engine_thread))
> >
> > And this works wonderfully for my custom engine.
> >
> > But now I wrote a engine using Swing. And I don't have control over
> > when the Swing thread is started. So there's no way for me to create a
> > thread-local binding to use my library.
> >
> > eg. I can't do this:
> > (binding [*my_environment* (new_environment)]
> >  (start_swing_event_thread)
> >  (.setVisible (new_engine)))
> >
> > So is there anyway for me to push a thread-local binding, when the
> > thread has already been started?
> >
> > Or is there a clean workaround for this problem? Instead of having to
> > resort to passing *my_environment* around through function parameters.
> >
> > Thanks a lot
> >  -Patrick
> > >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to