tl;dr in a self-fulfilling prophecy kind of way, there are no benign data-races. So the compiler can assume no-one would write a data race. Therefore it can make aggressive optimisations that render what would otherwise have been a benign race actively dangerous.
Granted the danger here is mainly theoretical, and the main problem for me is that turning off ThreadSanitizer because of this issue means that other more dangerous issues in my code (rather than the postgres client code) won't be found. But the above is the reason why ThreadSanitizer folks don't want to put in any "you can ignore this race, it's benign" functionality, and told me that the right thing to do was to contact you folks and get a fix in upstream...
> As far as I can tell, the static variable in question is a hack to allow a > couple of deprecated functions that are already unsafe to use > (PQescapeString and PQescapeBytea) to be fractionally less unsafe to use.
I don't see that making those be some other datatype would improve anything usefully. (1) On just about every platform known to man, int and bool are going to be atomic anyway. (2) The *actual* hazards here, as opposed to theoretical ones, are that you're using more than one connection with different settings for these values, whereupon it's not clear whether those deprecated functions will see the appropriate settings when they're used. A different data type won't help that.
In short: this warning you're getting from ThreadSanitizer is entirely off-point, so contorting the code to suppress it seems useless.