If you don't load the data until after the threads are spawned, isn't it the same deal, i.e. you mark it shared or else it's per-thread? I don't see the advantage in waiting, unless you know you only need the data in some of your threads.
If you have readonly data that is needed by many/all threads, mark it shared and you only get one copy (plus a few shared references).
If the data is globally modifyiable, mark it shared and have one copy.
If the data is locally modifiable, you need to have 1 copy per thread and it is far faster to clone it on mass than piecemeal via COW.
It would be great if threads could take advantage of COW, but at the moment they don't.
It doesn't make sense to use COW with threads, they can already share a single copy in memory.
COW only 'saves' if individual threads need to be able to modify local copies of small portions of large datasets. In this rare case, it is easy enough to a) share the large dataset (having set it readonly) and then b) copy the required portion to a thread-local non-shared storage during the process of modification.
In reply to Re^4: Perl Threads and multi-core CPUs
by BrowserUk
in thread Perl Threads and multi-core CPUs
by haidut
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |