RE: Invoking method in other thread context
[email protected] (Shmuel Fomberg) Thu, 10 Jan 2008 00:12:55 +0200
| Newsgroups | perl.ithreads |
|---|---|
| Message-ID | <000001c8530c$c9f3f320$6501a8c0@semuel7> |
>From: Dean Arnold >Sent: Wednesday, January 09, 2008 12:39 AM >> I am currently playing with C#. It have a nice feature that one thread >can >> call a function in other thread's context. (using the Invoke command, or >the >> asynchronic BeginInvoke command) >> This is useful especially in a GUI program, where one thread is handling >the >> GUI, and worker threads need to post status. >> >> So how do we do it in Perl? >> Sending signal and relaying the command somehow? > >Sorry for the double post...I just realized Thread::Apartment may solve >another part of your issue. It exports proxied method calls between >threads, so assuming thread A is running an instance of class XYZ with >method callme(), and thread B is running an instance of class DEF that >holds a proxy object $threadA to thread A's apartment, then thread B can >call >$threadA->callme() directly, ie, no closures needed. I read the document of Thread::Apartment, and it's one impressive module. However, I didn't quite understood what the 'urgent' methods are, and how they are different from regular ones? Also, the Thread::Apartment->new is creating objects inside the thread pool? It is not clear from the docs. If so, how do I create such object in the current thread? Btw, does every access to a shared variable is really catching a global lock? It's crazy. Why does it do it? >But the overhead issues still apply. Every inter-thread operation is expensive. Thanks, Shmuel.