[ 
https://issues.apache.org/jira/browse/MINIFICPP-1753?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gábor Gyimesi reassigned MINIFICPP-1753:
----------------------------------------

    Assignee: Gábor Gyimesi

> Remove the possibility of multiple initialization from controller services
> --------------------------------------------------------------------------
>
>                 Key: MINIFICPP-1753
>                 URL: https://issues.apache.org/jira/browse/MINIFICPP-1753
>             Project: Apache NiFi MiNiFi C++
>          Issue Type: Improvement
>            Reporter: Ferenc Gerlits
>            Assignee: Gábor Gyimesi
>            Priority: Minor
>              Labels: MiNiFi-CPP-Hygiene
>
> Quite a few controller services* use the pattern
> {noformat}
> void SomeService::initialize() {
>   if (initialized_)
>     return;
>   std::lock_guard<std::mutex> lock(initialization_mutex_);
>   ControllerService::initialize();
>   initializeProperties();
>   initialized_ = true;
> }
> {noformat}
> with an atomic {{initialized_}} variable.  This is probably intended as an 
> optimization to avoid locking the mutex, but that doesn't save much time, and 
> it can lead to the initialization being run multiple times.
> Put the {{if (initialized_)}} check behind the lock, and change the type of 
> {{initialized_}} to a plain {{{}bool{}}}.  This will make the code simpler 
> and it will make multiple initialization impossible, at the cost of making 
> {{initialize()}} run slightly slower when called a second or third time.
> [*] CoapConnector, JavaControllerService, MQTTControllerService, 
> DatabaseService and SSLContextService do this for sure; please check if there 
> are any others



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to