Threads!

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Threads!

 
0
  #1
May 12th, 2008
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
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Threads!

 
0
  #2
May 12th, 2008
>>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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 443
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 68
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: Threads!

 
0
  #3
May 13th, 2008
>>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.
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Threads!

 
0
  #4
May 13th, 2008
> 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:
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-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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: Threads!

 
0
  #5
May 14th, 2008
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-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....


Originally Posted by vijayan121
opinion seems to be divided
where do you stand vijayan121{and the other members of daniweb}?

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?

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
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Threads!

 
0
  #6
May 14th, 2008
> 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/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/
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: Threads!

 
0
  #7
May 15th, 2008
Thanks for the links!
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC