modified to support non-GNU compilers and to use calloc rather than malloc for per-thread reentrancy structure allocation.