Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One questions maybe not related to java

 
walter wang
Ranch Hand
Posts: 159
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All
I know how to implement multi thread in java
but how to do it in c and c++?
could any one show me a piece of sample codes?
thx.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One reason Java incorporates multi-threading into its platform is to avoid the detail and incompatibilities of thread systems on different OS platforms.
Any example will therefore be specific to an operating system or a family of closely related ones.
That said, in C/C++ they're written the same way. A C/C++ thread points to a starter function which in turns has all the code. One or more flag values are used to indicate certain behavior for the thread (priority, service or utility thread, etc.).
Here's an pseudo-example stolen from this book. It uses threading to load images from files into memory:

Not hard to see why people like what Java promises: a cleaner way to get to a complex but powerful programming technique. With a little thought, I could probably write the complete example in Java in fewer lines, and compile it on the first or second go.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic