On 3/21/19 7:43 AM, Плотников Павел wrote:
> Hello,
>
> The race relates to the usage of sqlite3GlobalConfig.isInit variable within 
> the sqlite3_initialize routine.
>
> As for 3.27.2 source code, the lines to be highlighted are
>
> sqlite3.c:153852: if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;
> and
> sqlite3.c:153938: sqlite3GlobalConfig.isInit = 1;
>
> The race is that there are no obstacles for the code from these lines to be 
> executed simultaneously: the if-expression gets evaluated with none of 
> synchronization applied.

That really isn't a data-race in the sense I am used to seeing it. At
least not at that level, there is perhaps one at a higher level using that.

I presume isInit is in a variable that is appropriately sized so that
the fetch and set are atomic operations (if not, then there MIGHT be a
race possible).

Yes, the test might give either a true or false answer depending on the
exact timing of the execution (does the test see the value before or
after the set), but that by itself isn't a race, as the mere fact that
you have parrallel execution says that both answers are allowed unless
something had been done to enforce a particular order. And in
particular, both answers would be possible even if you did add a mutual
exclusion between those two operations alone so they can't occur 'at the
same time', as it just depends on which one happened first.

Now, if the first line after seeing that isInit was false, does an
initialization that would be improper because it had already been done,
then THAT would be a data race, but its scope is bigger than just those
two lines.

-- 
Richard Damon

_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to