Comments (7)
Double bufferring appears to avoid the issue:
private $data = [[], []];
private $i = 0;
public function push($value):void {
$this->data[$this->i][] = $value;
}
public function drain():Volatile {
$data = $this->data[$this->i];
$this->data[$this->i] = new Volatile();
$this->i = +!$this->i;
return $data;
}
public function shouldWait():bool {
return count($this->data[$this->i]) === 0;
}
In some cases it's even weird, an array gets misplaced in the volatile. Someone is definitely screwing around with reused pointers there.
from pthreads.
Could you provide a runnable example? Thx!
from pthreads.
Here: https://github.com/joeyhub/aphpsync/blob/master/prototypes/test.php
from pthreads.
It's worth pointing out that I have a ref issue there. Eventually a command is sent to a thread which holds a reference up to a thread to notify when done. Nothing references the child threads, instead everything references the man in the middle.
I've been meaning to fix that later for graceful completion. I didn't really consider it related as I would expect it to hang on wait and it's been doing something weird hanging somewhere else. Though at first I didn't consider them related and would really expect a segfault, hang on wait or error, there's a good chance they are related as volatile's weirdness seems to set in a around about where the refs are gone and also if the handling of lost ref (hanging in weird places) is broken somehow then it wouldn't be surprising if it has other problems.
Still a bit of a headscratcher that double bufferring improves it (should remove any possibility for concurrent access in this particular use case) though I think it just reduces it.
from pthreads.
Adding graceful (though leaky) thread shutdown does appear to improve a lot of secondary issues I've been encountering with volatile even after the double bufferring.
However I'm not sure how reliable that graceful shutdown is. If the main thread dies it looks as though things will probably just hang. Similarly I practically need a thread monitor to potentially handle dead threads (try catch isn't reliable enough in my book either). I guess if thread death notified perhaps that could be enough though kind of ugly.
Worse still is tuning up the concurrency (workload per thread) and I got it to segfault. Whatever it is it's about one in 16000.
from pthreads.
Honestly I'd just do while($this->data->shift());
for draining.
from pthreads.
I've considered that although it's not really documented. Even then things shouldn't be hanging and segfaulting as they are. The current release definitely isn't stable or trustable.
Also relying on type juggling there isn't necessarily safe unless you always wrap the data in something that juggles to true. Similarly it doesn't seem to perform well that I would have to iterate if access to that needs to be synchronised.
Looking at the source those operations are only valid for Volatile anyway. Chunk actually deletes apparently so should probably be faster. Shifting each one isn't going to be all that efficient. Chunk should at least for example only need to lock once.
from pthreads.
Related Issues (20)
- Halting development of pthreads for 7.4 HOT 1
- Lost resource.
- Pool Completed Threaded Tasks Count Progress.
- Can not enable extension pthreads on PHP 7.2.15 Windows 10 Enterprise (x64) HOT 3
- sudo pecl install pthreads /usr/local/bin/pecl: 28: exec: /usr/local/bin/php: not found
- PHPIZE? HOT 1
- How to get unique php-extension instance for each php thread? HOT 6
- PHP 7.1.23 compile failed HOT 3
- Migrating to Pararell and Differences between these two extensions. HOT 1
- zend_mm_heap corrupted without sockets
- php-zts with pthreads not allocating tasks to free workers HOT 3
- Serialization of 'Closure' is not allowed in Worker HOT 5
- PHP7.4 HOT 2
- [BUG] PHP7.2 broken after this commit HOT 6
- Cannot install via pecl HOT 2
- Memory "leak" when passing large payload tasks to pool HOT 2
- windos load pthread.dll failed HOT 1
- Make not working HOT 1
- memory leak when pthreads in pthreads HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pthreads.