Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two functions task1() and task2().Now i want to do is that these two function should execute parallel at the same time and both should do its task at a time...So plz tell me how i can do it.I need complete code.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Feb-14 17:04pm    
What's your platform? Any preferences on the libraries to use? It's always useful to tag or mention your platform.
—SA
NoorKaximi 24-Feb-14 14:19pm    
Dev c++
Sergey Alexandrovich Kryukov 24-Feb-14 15:10pm    
I answered your question already. If I'm not mistaken, it does support C++11. Then, I would prefer standard C++ library.
—SA

1 solution

C++ does not have any threading facilities embedded in the language. It relies on some API or library implementing threading. It could be a particular OS API, or the library implementing some OS abstraction layer, that is, applicable to many OS. Here, you have some choice. One of the library is special because it is standardized. This is the C++ Standard Library:
http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library[^],
http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library#Thread_support_library[^].

Note that threading types have been introduced only with C++11: http://en.wikipedia.org/wiki/C%2B%2B11[^].

You can find some code samples in many places. For example: http://stackoverflow.com/questions/266168/simple-example-of-threading-in-c[^].

If you use anything older than that, you have many options: OS-specific APIs (I would advise you always tag your platform(s) in you questions), and many alternatives, such as boost:
http://en.wikipedia.org/wiki/Boost_library[^],
http://www.boost.org[^].

Boost also has its implementation of standard C++11 library, as well as Apache, for example. See the second link above for further information.

—SA
 
Share this answer
 
Comments
Usman Hunjra 22-Feb-14 11:24am    
+5 .. however I'm not at that level of expertise .. still student ..
But I really want to be ..
Sergey Alexandrovich Kryukov 22-Feb-14 20:42pm    
Thank you, Usman.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900