943,630 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1132
  • C++ RSS
May 12th, 2008
0

Threads!

Expand Post »
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
Similar Threads
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006
May 12th, 2008
0

Re: Threads!

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
May 13th, 2008
0

Re: Threads!

>>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.
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
May 13th, 2008
0

Re: Threads!

> 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/wg...007/n2320.html

the Boost.Thread library has been rewritten to align with c++09 proposals.
http://www.boost.org/doc/libs/1_35_0...ml/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:
Quote ...
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

Quote ...
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-Paral.../dp/0321228111

The Art of Multiprocessor Programming by Maurice Herlihy, Nir Shavit
http://www.amazon.com/gp/product/0123705916
Last edited by vijayan121; May 13th, 2008 at 10:46 am.
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
May 14th, 2008
0

Re: Threads!

thank you all, for your answers!

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

this phrase states my problem:

Quote ...
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-Buil.../dp/0201575949

which is freely availiable from here:

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

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


Quote originally posted by vijayan121 ...
opinion seems to be divided
where do you stand vijayan121{and the other members of daniweb}?

Quote originally posted by vijayan121 ...
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?

Quote originally posted by vijayan121 ...
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
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006
May 14th, 2008
0

Re: Threads!

> 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:
Quote ...
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/lis...reebsd-hackers
a somewhat dated reference is the book 'The Design and Implementation of the FreeBSD Operating System' http://www.informit.com/store/produc...sbn=0201702452
some other documents/papers that i'm aware of:
http://people.freebsd.org/~kris/scal...%20Preview.pdf
http://www.onlamp.com/pub/a/bsd/2008...70.html?page=4
http://ieeexplore.ieee.org/Xplore/lo...3/04215520.pdf
http://portal.acm.org/citation.cfm?i...GUIDE&dl=GUIDE
http://www.watson.org/~robert/freebs...05-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/
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
May 15th, 2008
0

Re: Threads!

Thanks for the links!
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: extracting integers using getline
Next Thread in C++ Forum Timeline: Using New





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC