PDA

View Full Version : Using multiple threads with C++




vgoklani
Feb 20, 2007, 10:37 PM
Hi,

I recently purchased a macbook Pro, and I would like to make use of the second CPU in my C/C++ programs. Could someone point me to a source for spawning threads using C/C++ on a mac? I do a lot of monte carlo simulations, and I would like to make use of the second cpu.



lazydog
Feb 21, 2007, 04:23 AM
Hi

There is something called Berkeley UPC (Unified Parallel C) over on the Apple download page under development tools. I've not tried it but I'd be interested in your thoughts if you do. Other than that I guess 'man fork'!

b e n

Palad1
Feb 21, 2007, 06:15 AM
Just use plain old posix threads if you want to use C

PThreads:

http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/articles/ThreadPackages.html#//apple_ref/doc/uid/TP40001474-110124
http://www.hmug.org/man/3/pthread.php

For c++ well you can wrap the pthreads or use the boost library, which has a nice oo threading API

http://www.boost.org/
http://www.boost.org/more/getting_started.html
http://www.boost.org/tools/build/v1/darwin-tools.html
http://www.boost.org/doc/html/threads.html

Good luck :)