The last two commits from me to stan-math StanHeaders_2.21 branch do this:

- The TBB is not used at all in cases whenever STAN_THREADS is
**not**defined. The TBB**is**used if STAN_THREADS is defined. - The
`stan::math::lgamma`

now**always**uses the boost implementation as I was not able to get things to work otherwise. It appears as if`_REENTRANT`

gets somewhere define**after**including`cmath`

. If that happens, then we have a catastrophe which causes`cmath`

to not export`lgamma_r`

, but stan-math will think it is defined. This means a ~5% performance it or so for Linux&macOS for models using this function heavily.

With the above changes I can have StanHeaders 2.21.0 and rstan 2.19.2 installed and successfully compile & load RBesT.

For the lgamma stuff I suggest that we take the small performance hit for now and tell people to use the new `_REENTRANT`

flag when they build their package (so put it in src/Makevars). As alternative we may introduce a `STAN_HAS_LGAMMA_R`

macro which people can set if they are sure that `lgamma_r`

is available.

Before I forget: Have you backported the boost::math::lgamma fixes which avoid overflow for large arguments of lgamma? That would be needed to get finite results from that function for arguments beyond 10^{25}.

Thanks for adding me to the author list.