Thanks a lot! BrowserUk. You are really great!

I'm sorry in fact there are some typos such as exported function names and missing the "1;" at the end of test.pm, etc. I should've double check my post...

But I am really weak on this part. The syntax to specify the subroutine-name in threads->create is confusing to me. And I guess maybe the latest release has addressed this problem (passing subroutine-name as string instead of code-ref). I have another question about code ref. In fact, I want my code to deal with unknown subroutine name beforehand. Instead, the name may be given in a parameter file in XML like the following:

<thread> <module>module_name</module> <subroutine>subroutine_name</subroutine> </thread>

A script reads the file and put modulename in var "$module" and subroutinename in "$subroutine". Then, what is the correct syntax to create a thread for "$subroutine"? I guess I have to use Module::Load to dynamically load a module first and then call threads->create to run a thread for a subroutine. Will this cause some problem?


Thanks!

And I rewrite 2nd part as follows. Please help. Thanks!


"Scalar leaked:1" error.
It is for simplicity that bareword "argument" is used in place of any type of variable.
_test.pl_
use threads; use test; my $thread=threads->create('forthread', (argument)); $thread->join(); exit(0);

-test.pm_
package test; require Exporter; our @ISA =qw(Exporter); our @EXPORT =qw(forthread); our @VERSION =1.0; sub forthread{ my (argument)=@_; my $thread=threads->create('another', (argument)); $thread->join(); return 0; } #forthread sub another{ return 0; } #another

NOTE: the error is reported when "argument" is one of the following:
- reference to scalar
- reference to array
- reference to hash
- hash

In reply to Re^4: "Attempt to free unreferenced scalar" and "Scalars leaked: 1" ? by licht
in thread "Attempt to free unreferenced scalar" and "Scalars leaked: 1" ? by licht

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.