I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2011-03-14 06:53:14.711938-07 by lowry76
Shared variables locked?
Hi, I'm new to perl-threads but have/want to use them for a very time-consuming problem. The script uses a large hash-ref with data the threads should work on. The hash just holds the data to work with but nothing is changed. Because I ran into memory probs when not sharing the hash I use the shared_clone() to share it and pass it to the different threads. What I experience now is that compared to the non-shared-option the performance drops to ~50%.
My first guess was that shared_clone somehow locks the shared variable as soon as one of the threads starts reading it because it's not declared read-only. But the source does not look like it.

Can someone explain the loss of performance? Should/could/do I have to declare everything read-only to overcome this?

Cheers,
lowry

Perl v5.8.8
threads::shared v1.36
OS: Ubuntu 4.2.4
Direct Responses: 13256 | Write a response
Posted on 2011-03-14 07:00:39.645142-07 by jdhedden in response to 13255
Re: Shared variables locked?
Shared variables are locked when accessed. This is needed so that changes to the data can be written and read properly. There is no concept of 'read-only' for shared variables. Without knowing more, I think you should investigate having the main thread feed the work data to the threads using queues.
Direct Responses: 13257 | Write a response
Posted on 2011-03-14 07:04:19.369755-07 by lowry76 in response to 13256
Re: Shared variables locked?
Thanks a lot. Was searching for an explanation for several days. I will consider queues.
Cheers,
lowry
Direct Responses: Write a response