[QGIS-Developer] On the danger of static C++ objects

Tim Sutton tim at kartoza.com
Wed Nov 15 22:15:25 PST 2017


Hi Even

> On 16 Nov 2017, at 00:58, Even Rouault <even.rouault at spatialys.com> wrote:
> 
> Hi,
>  
> There was a frequent crash in PyQgsServerWMS on Travis that I've hopefully fixed per 
> https://github.com/qgis/QGIS/commit/581d0d30ca89a213b1ba1a56a3fe2af5c896eacd <https://github.com/qgis/QGIS/commit/581d0d30ca89a213b1ba1a56a3fe2af5c896eacd>
>  
> This is the opportunity to raise attention on the danger of using this pattern:
>  
> static SomeClass singletonInstance;
>  
> where ~SomeClass() does some non trivial work in its destructor, and in particular calling other libraries (such as in the above mentionned case). Depending on the order into which libraries are unloaded and objects destroyed,  ~SomeClass() might call a function of a library which has already been unloaded, leading to crash.
>  
> So I'd suggest rather using a pointer approach (which admitedly makes constructing the singleton in a thread-safe way a bit harder), and explicitly deleting the singleton at appropriate and explicit time.
>  
> Unless someone is aware of a better approach.
>  
> By the way, is there somewhere in the tree a developer guide where we can collect such knowledge ?

We have:

https://www.qgis.org/en/site/getinvolved/development/qgisdevelopersguide/index.html

Source for which is here:

There is a ‘fix me’ link in the bottom of each page in the guide which will take you to the sphinx sources.

Regards

Tim

>  
> Even
>  
> -- 
> Spatialys - Geospatial professional services
> http://www.spatialys.com <http://www.spatialys.com/>_______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org <mailto:QGIS-Developer at lists.osgeo.org>
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer <https://lists.osgeo.org/mailman/listinfo/qgis-developer>
—







Tim Sutton

Co-founder: Kartoza
Project chair: QGIS.org

Visit http://kartoza.com <http://kartoza.com/> to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171116/cb91a550/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KartozaNewLogoThumbnail.jpg
Type: image/jpeg
Size: 6122 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171116/cb91a550/attachment-0001.jpg>


More information about the QGIS-Developer mailing list