I'm trying to get a pell program written and thread it. The problem is that I have read that some modules are not "thread-safe", how do I know if a module thread is secure? I have looked around for a list and have not searched one.
I often use (Text :: CSV_XS) to test a module: I tried to exclude the following code:
Strictly use ; Use warnings; Use threads; Use thread: share; Text required: CSV_XS; My $ CSV = Text: CSV_XS- & gt; New ({Binary = & gt; 1, EOL = & gt; "\ n"}) or die ("CSV can not be used:". Text: CSV-> Error_Diag ()); Open your $ output, "& gt ;: encoding (y8)", "test csv" or die ("test.csv: $!"); Share ($ CSV); My $ thr1 = Thread-> Create (& say hello ('1')); My $ thr2 = thread- & gt; Create (& amp; say hello ('2')); My $ thr3 = Thread-> Create (& amp; amp; say hello ('3')); Said hello {mine ($ num) = @_; Print ("Hello thread number: $ num \ n"); My @row = ($ num); Lock ($ CSV); {$ CSV- & gt; Print ($ Output, \ @Oro); $ Output- & gt; Autoflush (1); } # Lock # sayHello The output I get is the following:
Hello thread number: 1 split defect
Does this mean the module thread Is not safe, or is it another problem?
Thanks
Generally speaking, core and high-visibility module Are thread-protected unless their documents otherwise say otherwise.
He said, there is some misunderstanding in your post:
-
share ($ CSV)
This < Code> $ CSV (a blessed Hashref). Normally, you want to start pre or, perhaps in this case, to start complex objects, something dumb between the thread$ lockvariable
$ CSVholds state for the underlying Xs, this can be undefined behavior.
But this is not your default signal. -
Thread-> Create (& say hello ('1'));
You are accidentally callingHalo (1)in the main thread and the context of its return value tothreads-> create ()as a (bogus) start routine. You say:thread-> create (& say hello, '1');But this is not your segfault.
( Edit ) Just to make it clear - A bad start is not the risk of regular SEGV in any case here.
Threads: : Createcomplains correctly that if an unknown subroutine has been passed in the name or non-code referee. In your case, however, you are very quick to reach out to deal with this error.) -
The encodings are not thread-protected.
Again, theencodingmodule is not thread-safe. Here is the smallest possible code that I can reproduce your symptoms:threads Use; Open your $ output, "& gt ;: encoding (y8)", "/ dev / null" or die $ !; Threads-> Create (sub {}) - & gt; Join;with perl 5.12.1 threads - 1.77 on i686-linux-thread-multi, if you are interested leave "UTF8" magic, and it works just fine is.
Comments
Post a Comment