No surprise, those are near-impossible to avoid. I mean, a simple:
if(check(resource)) {
use(resource);
}
is already vulnerable, unless you somehow make the entire piece of code run atomically.