Thread: [Camelbones-devel] threading
Brought to you by:
shermpendley
From: Tom I. <to...@je...> - 2004-03-20 23:22:28
|
I'm going to regret this, I can tell. I've been writing increasingly crazy stuff in camelbones, it's a really lovely system, but it's not at the point that I want threading. I could probably live without it be re-writing things to use the proper NS classes to download stuff in the background, but frankly I like being able to use which ever from the perl and Cocoa metaphors is more handy at the time. So I want threads. I've been getting very weird and non-predictable behaviour when trying it, though. Is this likely to be my fault, or is this just not gonna happen? .tom |
From: Sherm P. <sh...@do...> - 2004-03-21 01:54:28
|
On Mar 20, 2004, at 6:22 PM, Tom Insam wrote: > So I want threads. > > I've been getting very weird and non-predictable behaviour when trying > it, though. Is this likely to be my fault, or is this just not gonna > happen? I've been afraid to try it. ;-) Threads in Perl are a moving target. Even aside from the fact that the Apple-supplied Perl for 10.1 & 10.2 didn't have threading enabled because of issues with Apple's libc, the API has completely changed from 5.005 to 5.6, and again from 5.6 to 5.8. Whenever it comes up on a Perl group or list, the response has invariably been "don't do it, threads ain't soup yet." Still, Cocoa's threads are nothing but a very thin wrapper over pthreads, and you can use both NSThread and low-level pthreads functions in an app. So if Perl is using pthreads, I'd tend to think it should be possible. Probably not very easy - nothing about threading ever is - but possible. It's definitely not something I want to tackle for 0.2.x though - and probably not for the initial 0.3.0 release either. sherm-- |
From: Sherm P. <sh...@do...> - 2004-04-02 11:59:25
|
On Mar 20, 2004, at 6:22 PM, Tom Insam wrote: > I've been getting very weird and non-predictable behaviour when trying > it According to its perldoc page, "use threads;" needs to be called as early as possible, and can't be called from within an eval "", do, require, or use. That might be causing problem, because main.pl is read into a string and called with eval_pv() - essentially, the whole program is being eval'd. So I've made a slight change to CBPerl.m, so that if USE_ITHREADS is #define'd, -Mthreads is passed as an argument to perl_parse(), with the same effect as if it were passed on the command line. There's no way to call it any earlier that I can see. The change doesn't seem to have any negative effect on non-threaded apps, so I've checked it in to the maint-0-2 branch. Could you have a look at it, and see if it improves things at all for your threading experiments? Also - keep in mind that AppKit isn't completely thread-safe. So, you should only send messages to GUI elements from within the main thread. sherm-- |
From: Tom I. <to...@je...> - 2004-04-02 13:29:55
|
On Apr 2, 2004, at 12:59, Sherm Pendley wrote: > So I've made a slight change to CBPerl.m, so that if USE_ITHREADS is > #define'd, -Mthreads is passed as an argument to perl_parse(), with > the same effect as if it were passed on the command line. There's no > way to call it any earlier that I can see. > > The change doesn't seem to have any negative effect on non-threaded > apps, so I've checked it in to the maint-0-2 branch. Could you have a > look at it, and see if it improves things at all for your threading > experiments? First cut, this seems to work. I've made CamelBrainz (https://dev.jerakeen.org:8080/svn/tomi/Projects/CamelBrainz) use threads for the searching phase, and it's massively improved. But bear in mind that CamelBrainz is a horrible nasty mess of dependancies - you'll need Mac::Glue, for a start.. I'll do a nicer release of it when it does Applescript the Right Way.. > Also - keep in mind that AppKit isn't completely thread-safe. So, you > should only send messages to GUI elements from within the main thread. Yes. The solution I'm using is to start a timer that fires once a second, and watches a queue for messages. The thread does the searching, and puts results onto the queue. Seems the safest way of handling it... .tom |