Sunday, April 26, 2009

Multi threading in c/c++

Although the feature of multi threading is not supported in c/c++ but I have to implement it in c++ for project
It could b done using some system files but still I dont know how to do it....
could u help me..............

suppose you could take thread building blocks (google!) and call it your own, but somebody wouldn't believe ya

Multithreading is supported by OS not by C++ compiler. So if ur OS supports Multi Threading u can do it. I believe these days all OS supports Multithreading, So I dont see any problem why u cant use it.

look for boost threads or pthreads.

as u said ,if am not wrong UNIX developed in C and supports multithreading.

use pthread.h header file.

Though its right no compiler comes with threading support but then no language comes with printing on console support.

So every ;language would provide a set of libraries or whatever they think is reqd. to make a programmer's life easier. but if something is not available in library you have two choices, write your own functions or use a third party library or hope that your platform has some system library for it.

Since C is ancient when compared to languages like C++ or JAVA, they didn't think something like threads is reqd. in the library. I dont even know if threads existed when K&R created C.

But JAVA provides threads and they call that "library" JAVA threads

For C, there is an open source library called pthread, which is POSIX compliant, free, open source and of course platform independent due to POSIX.

For a C++ programmar, I dont know if there is any thread library written in OOP and widely accepted, all you can do is use pthread C library as C++ is almost backward compatible with C.


What i understand is that people who work on Standardizing C++ have proposed to come up with a C++ thread library in STL by 2009 or 2010.

i hope there must be something used by core C++ programmers for threading or i have no idea if a C++ version for pthread is available.

Try google and see what it throws to you.

u can also try fork() function which creates
multiple simultaneous process threads as per
requirement. but this function depends on OS
so your machine's OS must be supportive.

There are lots of libraries in C++ that are supporting it, and may be later on STL supports it too, but I can't understand being a C++ programmers u need to think or wait for the libraries to make ur life easy, if u wanna easy life go for Java or .NET. Understand concepts of OS and the APIs. Threading is one of the key features of designing ur project. As u r C++ programmer u got the flexibility in making ur own threading model suiting ur project. Threading is totally different in Windows and Unix (so undersand it). So appreciate the language which will make ur life easy when u r going to be Software Architect.

C++ goes with the theme -- Not to re-invent the wheels.

But your point is certainly not in-correct. Basically the decision is of the designer.

Digressing to JAVA/.net can not be easy because, the flexibilty of JAVA and .net comeswith the compromise of JVM/.net framework.

So the decision is certainly with the designer.

What goes in the library in any language is a set of feature everyone deems necessary and generic.

And does one need to wait or not entirely depends on when is the change coming.

@Zaman, i didnt use the word ancient in regular sense,

may be i should have said "created earlier"

the point is with the availability of wonderful third party open source libraries, C does not need to extend its standard libraries. from threading to GUI everything is available.

My knowledge of C++ libraries is certainly limited. But in general it is true that C++ yet does not have the equally rich set. The very reason they need to extend STL and they have to fight JAVA.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.