I am using perl v5.12.2, threads v1.75, threads::shared v1.32.
My shenanigans with the semaphores and the detaching was a desperate attempt to plug the memory leak but of course you're right, it was useless. As others replied this could be an underlying problem with pthread. For now I'll rewrite the code to reuse threads.