[ 
https://issues.apache.org/jira/browse/AVRO-2722?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17436593#comment-17436593
 ] 

Thiruvalluvan M. G. commented on AVRO-2722:
-------------------------------------------

The cost of construction for the {{boost::mt19937}} RNG could be high and doing 
it once per file, while not terrible, could be expensive. It may be better if 
we implement the original idea in the ticket of having a mutex. The cost of 
obtaining lock is fixed irrespective of the complexity of RNG construction. 
This also tackles the possibility of two threads constructing the RNG at the 
same second and thus generating the same sync.

> impl/DataFile.cc use of boost::mt19937 for DataFileWriteBase::makeSync is not 
> thread safe
> -----------------------------------------------------------------------------------------
>
>                 Key: AVRO-2722
>                 URL: https://issues.apache.org/jira/browse/AVRO-2722
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: c++
>    Affects Versions: 1.9.1
>         Environment: Issue can be reproduced in Linux with clang and on 
> Android arm64 and armeabi with android NDK r19c.
>            Reporter: Dan Schmitt
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Critical
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The single instance of random is not thread safe, and can seg fault.
> It can be fixed with a global std::mutex next to the global boost::mt19937 
> generator and a std::unique_lock in the method, or by creating the 
> mersenne_twister_engine as a local variable in the function.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to