Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Insight needed: Perl, C, Gtk2, Audio, Threads, IPC & Performance - Oh My!

by jdhedden (Deacon)
on Jun 01, 2006 at 15:56 UTC ( [id://553078]=note: print w/replies, xml ) Need Help??


in reply to Insight needed: Perl, C, Gtk2, Audio, Threads, IPC & Performance - Oh My!

Let me address your threading questions because they are rather generic in nature.
Now that perl has some measure of thread support (based on pthreads it seems), I might be able to use that.
Perl's threading support has improved greatly since its introduction in 5.8.0, and continues to improve. As such, you should use the most recent version of Perl (currently 5.8.8) for your system, and be sure to install the lastest versions of the threads and threads::shared modules. This will give you the latest feature sets as well as the best reliability.
* Is it possible to share perl objects between threads?
Objects can be shared between threads. However, the class must be written to specifically support threads and sharing. You can do all this from scratch, of course, but I strongly recommend an object support module that handles all the necessary technicalities for you. Object::InsideOut is one such module that is very full-featured and fully supports threads and sharing.
* If so, how efficient is that?
Thread data sharing is implemented using a tie methodology. Sharing objects between threads is as efficient as sharing any other data.
* Does it also work with XS backed objects?
Yes, but you have to make sure it is done correctly. As an example, you might look at Math::Random::MT::Auto which has XS-backed objects, and uses Object::InsideOut for its object paradigm.
* If I can't share perl objects, would it be possible to create a 100% C thread that directly calls into the C code/data in another thread?
Since you can share objects between threads, this question is moot. However, regarding the technicalities of using C-based threads from Perl, it should be possible if you don't access any Perl data in those threads, but I would imagine that such an approach would be fraught with difficulities.
* Are there any pitfalls I should look out for?
If you want to write your classes to handle all the details of threading and sharing yourself, then you need to be cognizant of the CLONE method (see Making your module threadsafe), and how to create sharable objects (see annotations for threads::shared).

However, if you use Object::InsideOut, all these details are taken care of for you.

Regardless of your approach, you need to be conversant with the threads and threads::shared PODs.


Remember: There's always one more bug.
  • Comment on Re: Insight needed: Perl, C, Gtk2, Audio, Threads, IPC & Performance - Oh My!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553078]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-18 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found