Is it possible to code any C multi-threaded program in C++?

Feb 29, 2012 at 11:04pm
I know that C++ is basically 100% backwards compatible with C as long as the correct libraries are linked but I was wondering if it would worth my while to use C++ for multi-threading instead of C.

The reason I ask is because I have a class where we need to write multi-threaded apps and the book we have is in C and the Prof. is not familiar with C++ but said that if we can make it work in C++ than that's fine.

Would it be advantageous to try and multi-thread in C++ or would it be just as easy in C?
Feb 29, 2012 at 11:56pm
Yes.
Mar 1, 2012 at 12:04am
If your prof is open to using c++ then I'm guessing he is open to you using boost and if so I would recommend boost for it's simplicity.
Mar 1, 2012 at 12:43am
boost for it's simplicity.


My head just exploded. I don't think I ever heard anyone call boost simple before.

Don't get me wrong, it's not a bad suggestion... boost is great. It's just anything but simple.
Mar 1, 2012 at 12:44am
Try to find a C++11 compiler so you can use std::thread :)
Mar 1, 2012 at 3:33am
I agree, boost.threads are incredibly simple after POSIX threads.

Of course now both C++ and C have their own threads.. but I still use boost in production.

PS: C++ is not "basically 100%" compatible with C, although for unsophisticated C programs, it's usually easy conversion.
Last edited on Mar 1, 2012 at 3:34am
Mar 1, 2012 at 3:34am
boost.threads are incredibly simple after POSIX threads
That's because C++ interface ought to be easier to use than C interfaces from C++.
Mar 1, 2012 at 3:35pm
What libraries are you going to use..? Some are quite straight forward to implement, like openMP, pthread, some are NOT. Easy meaning, you don't have to thinker with the code to get it paralleled.
Mar 1, 2012 at 5:10pm
closed account (S6k9GNh0)
You can abstract the use of C++ behind a C API. I do it all the time with void pointers (which people don't seem to like...).

However, there's no real reason to use C++ aside from using the extra functionality a certain C++ library provides. I don't know of a cross-platform C thread library to be honest although one is very possible.

glib might provide one as it provides just about everything. Although, I've seen some *very* questionable implementations in glib so use at your own risk.
Last edited on Mar 1, 2012 at 5:12pm
Topic archived. No new replies allowed.