Fixed thread ID allocations

Andrea Zoppi