Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, Do you know if there are plans to have real Windows threads in a future perl version, 5.x or 6.x that can share the memory and would be able to share objects? I am asking because creating a multi threaded perl program that need to share many objects is impossible and require using very complicated ways of doing things. Thank you. Octavian
Post Follow-up to this messageOn Sat, 2008-04-19 at 11:29 +0300, Octavian Rasnita wrote: > Hi, > > Do you know if there are plans to have real Windows threads in a future pe rl > version, 5.x or 6.x that can share the memory and would be able to share > objects? Ouch. "real Windows threads" Currently perl uses ithreads. If there was a plan to do things differently I would hope POSIX threads would be the method. > > I am asking because creating a multi threaded perl program that need to > share many objects is impossible and require using very complicated ways o f > doing things. I ran into the same problem and just redesigned my program to now share objects. > > Thank you. > > Octavian
Post Follow-up to this messageFrom: "Chris Fowler" <cfowler@outpostsentinel.com> > I ran into the same problem and just redesigned my program to now share > objects. Oh, this sounds good. Can you please tell me how can this be done? I want to use perl for creating apps with WxPerl and share objects among threads. I've seen that there are ways to just share scalar variables and send messages to windows or use POE multitasking which is not very easy. I would like to be able to share WxPerl objects and database handles among threads. Thank you very much! Octavian
Post Follow-up to this messageOctavian Rasnita wrote: > From: "Chris Fowler" <cfowler@outpostsentinel.com> > > > Oh, this sounds good. Can you please tell me how can this be done? > I want to use perl for creating apps with WxPerl and share objects among > threads. > > I've seen that there are ways to just share scalar variables and send > messages to windows or use POE multitasking which is not very easy. > I would like to be able to share WxPerl objects and database handles > among threads. > > Thank you very much! > > Octavian > > Wrt database handles, I presume you mean DBI handles. Alas, DBI isn't fully threadsafe. There has been some work to provide a thread pooling feature, but its (at best) experimental. I'll offer DBIx::Threaded as a possible alternative, but its a bit heavyweight. wxPerl describes some details wrt threads: http://search.cpan.org/~mbarbon/Wx-...b/Wx/Thread.pod but I'm otherwise ignorant of it. (tho pleasantly surprised there's any threads related documenation, given the sparseness of the rest of wxPerl's docs...) You can't really share wx objects, but instead use msg passing between threads (same applies to Perl/Tk, and probably most other GUI libs, due to the event control loop). Good luck, Dean Arnold
Post Follow-up to this messageCorrect about DBI. I've even ran into problems doing forks with db handles.
Post Follow-up to this messageI read on many places that the database handles can't be shared successfully and I also guess the GUI windows objects can't be shared, but I heard that this is possible under other languages and that's why I wanted to know if it would be possible to create a multithreading program in perl as easy as in other languages like C# or Java. I prefer to not need to send messages to windows, and act in each window based on those messages, because it would be too low-level programming and I would need to learn too many things about the GUIs I use, and some of them don't have a very good documentation and it would be pretty hard. Basicly what I intend to do is to create a client-server application where the client is made using WxPerl and where the client should have some worker threads that download some XML files from the internet, some css files from other web sites on a user-defined schedule, store them in a local database made with SQLite or something else, communicate with the server part of the application by request or based on a schedule defined by the user, and display the data in more windows. The client should not block if it downloads something from a certain source, or when the user sends something to the server. Even if I won't use a shared database handle, this wouldn't be very hard, because I could create separate database connections for each thread, but the problem is that I would still need to access the WxPerl windows from the worker threads. Passing messages to a window might not seem very complicated, but if there are more windows, and many rules based on admin's preferences, on user's schedule, or by user's request, might make the program a spaghetti application. I think what I want to do should be a very common client-server application. Do you know if I could find somewhere such sample apps made in perl? Thank you. Octavian ----- Original Message ----- From: "Christopher Fowler" <cfowler@outpostsentinel.com> To: "Dean Arnold" <darnold@presicient.com> Cc: "Octavian Rasnita" <orasnita@gmail.com>; <perl-ithreads@perl.org> Sent: Saturday, April 19, 2008 10:30 PM Subject: Re: Perl threads under Windows > > Correct about DBI. I've even ran into problems doing forks with db > handles. > > >
Post Follow-up to this messageOctavian Rasnita wrote: > > Passing messages to a window might not seem very complicated, but if > there are more windows, and many rules based on admin's preferences, on > user's schedule, or by user's request, might make the program a > spaghetti application. I think what I want to do should be a very common > client-server application. Do you know if I could find somewhere such > sample apps made in perl? > My suggestion is to try perlmonks.org and do a super search for "Tk threads"; its been discussed and coded there numerous times. Here's the most recent: http://www.perlmonks.com/?node_id=522177 FWIW: you might take a look at Thread::Apartment to see if you can wrap Wx in its own thread, and make it look like you're passing objects around. I'd started to create a Tk::Threaded for Perl/Tk based on that, but it needs inter-thread tie()'d operations, which aren't available via the current ithreads environment. - Dean
Post Follow-up to this messageAnother suggestion is to share the DB connection info like host, user, database, passwd, etc. Then in the thread open, execute, close. This has worked for me. db handles can be used in a perl program that is threaded. you just can't share a db handle between threads. I don't think they work across a fork either. On Sat, 2008-04-19 at 14:33 -0700, Dean Arnold wrote: > Octavian Rasnita wrote: > > My suggestion is to try perlmonks.org and do a super > search for "Tk threads"; its been discussed and > coded there numerous times. Here's the most recent: > > http://www.perlmonks.com/?node_id=522177 > > FWIW: you might take a look at Thread::Apartment to see > if you can wrap Wx in its own thread, and make it > look like you're passing objects around. I'd started to > create a Tk::Threaded for Perl/Tk based on that, but > it needs inter-thread tie()'d operations, which aren't available > via the current ithreads environment. > > - Dean
Post Follow-up to this messageThank you Dean. I will search on perlmunks and try to see if I can adapt something for WxPerl. Unfortunately I can't use Tk because this GUI is absolutely inaccessible for screen readers and I am blind, so I can't test if it even works. Octavian ----- Original Message ----- From: "Dean Arnold" <darnold@presicient.com> To: "Octavian Rasnita" <orasnita@gmail.com> Cc: <perl-ithreads@perl.org> Sent: Sunday, April 20, 2008 12:33 AM Subject: Re: Perl threads under Windows > Octavian Rasnita wrote: > > My suggestion is to try perlmonks.org and do a super > search for "Tk threads"; its been discussed and > coded there numerous times. Here's the most recent: > > http://www.perlmonks.com/?node_id=522177 > > FWIW: you might take a look at Thread::Apartment to see > if you can wrap Wx in its own thread, and make it > look like you're passing objects around. I'd started to > create a Tk::Threaded for Perl/Tk based on that, but > it needs inter-thread tie()'d operations, which aren't available > via the current ithreads environment. > > - Dean
Post Follow-up to this messageI understand that the perl threads (at least under Windows) are actually a kind of separate processes that don't share the memory unlike the Windows native threads, and that's why they are not so slim as the Windows threads and why they can't share objects. Octavian ----- Original Message ----- From: "Chris Fowler" <cfowler@outpostsentinel.com> To: "Dean Arnold" <darnold@presicient.com> Cc: "Octavian Rasnita" <orasnita@gmail.com>; <perl-ithreads@perl.org> Sent: Sunday, April 20, 2008 2:36 AM Subject: Re: Perl threads under Windows > Another suggestion is to share the DB connection info like host, user, > database, passwd, etc. Then in the thread open, execute, close. This > has worked for me. > > db handles can be used in a perl program that is threaded. you just > can't share a db handle between threads. I don't think they work across > a fork either. > > > > > On Sat, 2008-04-19 at 14:33 -0700, Dean Arnold wrote: >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.