After installing Leopard, I have noticed that some of the applications I have written have begun to misbehave after running for a while. It turns out that they are no longer able to create new threads, despite having plenty of free memory and only a handful of other threads running.

The culprit is a change in behaviour when calling pthread_create on Tiger vs. calling it on Leopard. On Tiger, it is possible to create millions of threads without worrying about cleaning up after them. This has changed in Leopard: Now, it is only possible to create 11002 (I wonder were that magical constant came from) threads before additional new threads can not be created. The following snippet of code demonstrates the issue:

To compile the code, put it in a file called pthread-test.c and compile it by running gcc -Wall -o pthread-test pthread-test.c from a terminal. Then run the binary by typing ./pthread-test . After a few seconds, the program will give the following output:

The fix to this particular problem is to always explicitly detach threads that you do not intend to pthread_join() with later on. That is, once the thread has been created, it should be detached as follows:

About me
My name is Daniel Stødle. I live in Tromsø, Norway, at 69.66° North. By day, I work as a researcher at the Northern Research Institute in Norway; by night, I run my company SCSC. I do most of my development on and for Mac OS X. My research is geared towards interaction with and visualization of geospatial data. Read more on my personal page.