Multithreading on Mac OS X

I've recently read somewhere on the Web that Mac OS X has no concept of multithreadiing. I'm assuming from this that OS X uses some form of coarse-grained scheduling based on task/process. How does the Java VM run on OS X? Java apps rely on multithreading within the VM.

Thanks.

Windows Vista

Posted on Jun 2, 2009 8:35 AM

Reply
18 replies

Jun 2, 2009 12:04 PM in response to IPEnthusiast

IPEnthusiast,

When you open the Terminal, you can type

ps -ax


and list all the processes in Mac OS X as individual threads.

When you read the website from Apple Developer, any programmer following Apple's guidelines will make at least Posix compliant threads if not Cocoa. There are naturally some issues with Carbon programming, stated here:

http://www.macintouch.com/m10carbon.html

So as long as you are running all non-legacy code, you should be good to go.

Jun 2, 2009 12:23 PM in response to IPEnthusiast

IPEnthusiast wrote:
Well, simply because Mac OS X is based on UNIX, it can't be assumed that the OS is multithreaded. Multithreading is a concept that came around way after the first UNIX OSes were developed.


Multithreading is mandated by Posix, and OS X 10.5 is fully Posix compliant. In fact it is UNIX 03 registered, and therefore it is Unix. See Mac OS X Leopard: Technology for more.

If you want to know more about threads in OS X, try
man 3 pthread

And this actually manifested itself in earlier versions of the Linux kernel that simulated threads by actually launching a whole process in place of a thread, to take advantage of the process scheduler. Linux was firmly based on old UNIX code, I believe the implementation was called Minix.

On the other hand, Linux and Minix were, and are, not Unix. Neither were "based on" old Unix code.

Jun 3, 2009 8:45 AM in response to a brody

I might ammend this post saying, there is a Developer forum where you can ask what Mac OS X does support, or how it supports a certain feature, rather than off the bat assume it does not support it. It is found here:

http://discussions.apple.com/forum.jspa?forumID=727

Additionally you can search the resources at http://developer.apple.com/

I found the above link about Thread Local Storage though with the help of Google.

I would encourage to you dispell any myths you've heard, by asking how to approach a technical issue, instead of saying it does not support XYZ.

Jun 2, 2009 9:13 AM in response to IPEnthusiast

Since you sound like a knowledgeable programmer, I will assume you have installed or will install soon the Developer Tools package. When that is done, go into the /Developer/Applications/Performance Tools/ folder and run Thread Viewer. You will either attach it to an already-running application or use it to start a new application, after which you will get a window where you can see in real time all the threads being used by the chosen application, down to the specific code being executed. Knock yourself out... 😀

Side note: I'd suggest you register yourself on the [Apple Developer Connection|http://developer.apple.com> (there's a free registration option) so you can download the very latest version of the Developer Tools, as well as many other development goodies.

Jun 2, 2009 9:15 AM in response to IPEnthusiast

Hi IPEnthusiast;

With OS X being based on Unix, I would have to say that it is multithreaded. It is most certainly more capable of multithreading then anything from M$.

In the years of IT support that I have done, I can't believe how poorly Windows is at multithreading and utilizing multiple CPUs. So many times the customer would for Windows and later we would run Unix on the same server hardware and get significantly better perform simply by migrating off of Windows.

Allan
User uploaded file

Jun 2, 2009 11:25 AM in response to Allan Eckert

Well, simply because Mac OS X is based on UNIX, it can't be assumed that the OS is multithreaded. Multithreading is a concept that came around way after the first UNIX OSes were developed. And this actually manifested itself in earlier versions of the Linux kernel that simulated threads by actually launching a whole process in place of a thread, to take advantage of the process scheduler. Linux was firmly based on old UNIX code, I believe the implementation was called Minix.

Jun 2, 2009 12:50 PM in response to Allan Eckert

And the robust combination of Windows Server/SQL Server has not figured atop the TPC OLTP benchmark with a poorly designed OS. While SQL Server itself uses its own scheduler, the underlying OS plays a very crucial part in how the database engine performs. Since the introduction of distributed partitioned views in SQL Server 2000, Microsoft has consistently blown the top off of the TPC benchmark. You just have to know how to tune these products.

Jun 3, 2009 6:56 AM in response to Allan Eckert

Actually, what OS X does not support is Thread Local Storage. At the extremity, if you need to spin off a bunch of threads that are based on the same function/method and if you don't have any need to share state between those threads, TLS simply makes each thread look like an independent method. But sharing state is the more common scenario in multithreading, so the OS can lend a very helping hand through its implementation of TLS there as well.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Multithreading on Mac OS X

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.