hi to everyone,

In this semester we are having a class concerning High Performace computing / Parallel processing...

In short i have the following questions:

--- We are using pthreads and C. I think that i can use pthreads in c++ code but is there any way to use threads in c++ ,in an object oriented manner?
{Like object oriented pthreads}

--- For everyone that has some experience with production code. Is it common for "everyday" applications (in todays multicore platforms) to use threads?

I use the term everyday to seperate scientific from non scientific applications{*}. I.e. if we open a text editor will we find threads inside?


Last but not least, can anyone propose sources for threaded programming.{Books, sites whatever it might help}. I have "googled" it, but i
was wondering if anyone with hands-on experience has something to say.


{*}:: i imagine that in scientific applications threads are used in things like matrix multiplication.

thanks for your time,
Nicolas

>>I think that i can use pthreads in c++ code but is there any way to use threads in c++ ,in an object oriented manner?
There might be some obscure c++ objects out there, such as the Microsoft Foundation Class (MFC) which is only useful for wring MS-Windows windows. Boost libraries have a threading class that.

>>Is it common for "everyday" applications (in todays multicore platforms) to use threads?
Yes, it is very common. If you are running MS-Windows start up the Task Manager, view the Processes tab then you can see how many thread each process has started. You might have to select View --> Options to get that column.

>>I have "googled" it, but i was wondering if anyone with hands-on experience has something to say.

Theread aren't reall all that difficult to start. Here are a few google links you should read. You can ignore the ones about MFC unless you are using that which is doubtful.

>>I.e. if we open a text editor will we find threads inside?

Text editor will definitely be multithreaded. Imagine a scenario where you send one document for printing and are writing into another document. Almost every application we use in our day to day lives will be multithreaded. The fast CPU speeds, huge amount of RAM's in the systems today make it almost mandatory to write multithreaded code to take full advantage of the processor.

> is there any way to use threads in c++

the ISO standards committee (c++09) has voted voted in a number of concurrency extensions into the working draft (memory model, atomics library, basic threads, locks, and condition variables). an asynchronous future<T> type would be added later, but features like thread pools are deferred.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html

the Boost.Thread library has been rewritten to align with c++09 proposals.
http://www.boost.org/doc/libs/1_35_0/doc/html/thread.html

> Is it common for "everyday" applications (in todays multicore platforms) to use threads?

in windows, probably yes. threads have been widely used over the years.
in unix, probably no. fork is very efficient.
most of the push towards concurrency seems to be in the kernel (solaris, bsd), filesystems (zfs) and libc ( bsd's gemalloc, google's tcmalloc) right now.

opinion seems to be divided; here are two extremes:

I won’t be surprised at all if the whole multithreading idea turns out to be a flop, worse than the "Itanium" approach that was supposed to be so terrific—until it turned out that the wished-for compilers were basically impossible to write.
Let me put it this way: During the past 50 years, I’ve written well over a thousand programs, many of which have substantial size. I can’t think of even five of those programs that would have been enhanced noticeably by parallelism or multithreading. - Donald Knuth

http://www.informit.com/articles/article.aspx?p=1193856

Concurrency is the next major revolution in how we write software
Applications will increasingly need to be concurrent if they want to fully exploit continuing exponential CPU throughput gains. - Herb Sutter

http://www.gotw.ca/publications/concurrency-ddj.htm

> sources for threaded programming.

a great book: Java Concurrency in Practice by Brian Goetz
http://www.javaconcurrencyinpractice.com/

two other good books:
Patterns for Parallel Programming by Timothy G. Mattson, Beverly A. Sanders, Berna L. Massingill
http://www.amazon.com/Patterns-Parallel-Programming-Software/dp/0321228111

The Art of Multiprocessor Programming by Maurice Herlihy, Nir Shavit
http://www.amazon.com/gp/product/0123705916

thank you all, for your answers!

from this link.... http://www.ddj.com/cpp/184401518 is also helpful...

this phrase states my problem:

these libraries are almost universally C libraries and require careful use in C++

is there any tutorial ,{or} book for this?
[maybe the book Java Concurrency in Practice addresses this thing, but i haven't got it so far]


also i heard nice comments about this book:

http://www.amazon.com/Designing-Building-Parallel-Programs-Engineering/dp/0201575949

which is freely availiable from here:

http://www-unix.mcs.anl.gov/dbpp/

although published in 1995 it seems a bit old....

opinion seems to be divided

where do you stand vijayan121{and the other members of daniweb}?

in windows, probably yes. threads have been widely used over the years.
in unix, probably no. fork is very efficient.
fork is very efficient.

i can understand how you would solve server response problems with fork. But how you would solve others like i.e examining a 2d matrix?

most of the push towards concurrency seems to be in the kernel (solaris, bsd), filesystems (zfs) and libc ( bsd's gemalloc, google's tcmalloc) right now.

can you point to any articles concerning the concurrency in the kernel?{it seems really interesting...}


thanks again for your help!

-nicolas

> maybe the book Java Concurrency in Practice addresses this thing
no, it doesn't. it is a good book on concurrency issues in general, but discusses only java.

> where do you stand vijayan121
closer to Knuth than to Sutter. my experience has been that the extra synchronization overhead very often cancels out quite a bit of the performance gains. not to mention exponentially greater complexity of the software. it is much cheaper to just buy more machines than hire more (good) programmers.

> But how you would solve others like i.e examining a 2d matrix?
high performance mathematical/graphics/engineering computing would remain a niche area. again, i tend to agree with Knuth:

I know that important applications for parallelism exist—rendering graphics, breaking codes, scanning images, simulating physical and biological processes, etc. But all these applications require dedicated code and special-purpose techniques, which will need to be changed substantially every few years.

> can you point to any articles concerning the concurrency in the kernel?
freebsd:
not too many articles exist. to be current, you need to look at the source code. and the freebsd-hackers mailing list. http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
a somewhat dated reference is the book 'The Design and Implementation of the FreeBSD Operating System' http://www.informit.com/store/product.aspx?isbn=0201702452
some other documents/papers that i'm aware of:
http://people.freebsd.org/~kris/scaling/7.0%20Preview.pdf
http://www.onlamp.com/pub/a/bsd/2008/02/26/whats-new-in-freebsd-70.html?page=4
http://ieeexplore.ieee.org/Xplore/login.jsp?url=/iel5/4215472/4215473/04215520.pdf
http://portal.acm.org/citation.cfm?id=1251976.1252627&coll=GUIDE&dl=GUIDE
http://www.watson.org/~robert/freebsd/2005eurobsdcon/eurobsdcon2005-netperf.pdf

solaris:
book: 'Solaris Internals: Solaris 10 and OpenSolaris Kernel Architecture, Second Edition'
http://safari.adobepress.com/0131482092
articles at http://www.solarisinternals.com/wiki/

This question has already been answered. Start a new discussion instead.