diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-01-09 15:50:48 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-01-09 16:52:13 +0200 |
commit | 3ea459233a60ee737d0b637582f94024f3763797 (patch) | |
tree | 68688c9c564e69dccb66f8a97f2ee551a8968127 /src/mbgl/util | |
parent | 236afc03958cc729b3b8121a1c5a72660f0e9fa2 (diff) | |
download | qtlocation-mapboxgl-3ea459233a60ee737d0b637582f94024f3763797.tar.gz |
[core] Fix GeoJSONVTData ownership and life cycle
Before this change, the `GeoJSONVTData` instance was retained at the scheduled
lambda, which run on the worker thread represented by the `GeoJSONVTData::scheduler`
class member:
```
std::weak_ptr<GeoJSONVTData> weak = shared_from_this();
scheduler->scheduleAndReplyValue(
[id, weak, this]() -> TileFeatures {
if (auto self = weak.lock()) {
return impl.getTile(id.z, id.x, id.y).features;
}
return {};
},
fn);
```
It caused program termination in case `self` turned to be the last reference to `this`,
as the `std::thread` destructor was called from the thread it represented.
Now, only the `GeoJSONVTData::impl` class member is retained.
Diffstat (limited to 'src/mbgl/util')
-rw-r--r-- | src/mbgl/util/thread_pool.hpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/mbgl/util/thread_pool.hpp b/src/mbgl/util/thread_pool.hpp index e39c1abc73..9791ff9460 100644 --- a/src/mbgl/util/thread_pool.hpp +++ b/src/mbgl/util/thread_pool.hpp @@ -48,6 +48,7 @@ public: ~ThreadedScheduler() override { terminate(); for (auto& thread : threads) { + assert(std::this_thread::get_id() != thread.get_id()); thread.join(); } } |