Skip to content
Snippets Groups Projects
Commit 18174680 authored by Florian Schmaus's avatar Florian Schmaus Committed by Florian Fischer
Browse files

[LinuxVersion] Use "Construct on first use" idiom and add mutex

Use the "Construct on first use" idom for UTS Release (aka Linux
version) initialization. The previous implementation was fragle and
could lead to segfaults like

    __s2=0x7fffffffe480 "5.16.10-arch1-1", __s1=<optimized out>)
    at /usr/include/c++/11.2.0/bits/char_traits.h:409
    __n=<optimized out>, __s=0x7fffffffe480 "5.16.10-arch1-1", __d=<optimized out>)
    at /usr/include/c++/11.2.0/bits/basic_string.h:359
    __n=<optimized out>, __s=0x7fffffffe480 "5.16.10-arch1-1", __d=<optimized out>)
    at /usr/include/c++/11.2.0/bits/basic_string.h:354
    __str=..., this=0x7ffff7fbd2a0 <emper::lib::LinuxVersion::globalVersion[abi:cxx11]>)
    at /usr/include/c++/11.2.0/bits/basic_string.h:739
    at ../emper/lib/LinuxVersion.cpp:46
    at /usr/include/c++/11.2.0/ext/new_allocator.h:79

if globalVersion's constructor was not yet called. This is the so
called "static initialization order fiasco" in C++.

While the mutex may not be strictly requires, as we do not call
LinuxVersion's non-argument constructor nor getUtsRelease()
concurrently, it can not hurt to have one.
parent 6d2608c9
No related branches found
No related tags found
1 merge request!348[LinuxVersion] Use "Construct on first use" idiom and add mutex
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment