-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to share memory accross threads ? #332
Comments
Hey @camille-chelpi 👋 you are correct, this won't work anymore. You can read about the main change in philosophy from One of the reasons is also in your code. When accessing Hope this helps. |
I have this solution but it's not nice at all because I'm can't manage the concurence beetwen the unserialize() & serialize() inside a thread and it also mutliply the memory used by the number of thread
|
IDK the problem you are solving, but this works: <?php
$big_storage_elt = [];
$threads = array();
for($i=0;$i<5;$i++)
{
$thread = new \Parallel\Runtime();
$threads[] = $thread->run(function($index){
return [$index, 'value '.$index];
},[$i]);
}
//waiting end of each thread
foreach($threads as $thread) {
list($k, $v) = $thread->value();
$big_storage_elt[$k] = $v;
}
print_r($big_storage_elt); |
Perhaps you would also like to take a look at the code in this repo: https://github.com/realFlowControl/1brc |
Yes but it's cost much more memory and delay using futur & channel when you deal with huge array. |
It should be perfect if \Parallel\sync can have a function like this that could handle array as value also. something to study I guess |
I get your point and I'd like to learn more about the issues. Like how big will the |
How to share an object/array across threads without coping it accross a channel/futur in order to minimise memory usage ?
With pthreads (php 7.2), we could use Threaded but impossible to do it with Paralell ?
I would like to see as result:
The text was updated successfully, but these errors were encountered: