Hi monks,
I'm using perl since some time now and I just wanted to see some new aspects of it. So i started writing a Tk-Based mp3-player(-interface) in oop using threads.
The question is: How can i share objectes between threads?
Example:
I have my main application, a gui-object, a player and one object for each mp3-file (in @mp3s). The player is a loop that is started in a thread and listens on a Thread::Queue for instructions, polls the player (mpg321) and stores some information in another queue. The gui has its own loop.
The only way i figured out to let the player play a song was to push its filename directly in the thread::queue because @mp3s can not be shared. I think this is firstly ugly, secondly not really oop and i don't like it personally.
So if i could call a method in the player-module providing a shared mp3-object all my problems where solved...
Note: writing "my @mp3s : shared;" and filling it later with objects makes Perl say: "Invalid value for shared scalar"
Thanks in advance, Robert
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.