-2

Parallel programming or threading, it should be for Visual C++.

A function takes a large amount of time To complete, as a result the rest of the code will not be executed for ex

main()
{  
    timeconsumingcode();
    nextstep();
}

nextstep() Will not Take Place Until timeconsumingcode() gets over;

hence i want timeconsumingcode() and nextstep() to run simultaneously

I would like to know how we do it for Visual C++

2 Answers2

4

In C++11 you should be able to use std::async or, as @MSalters proposed in the comment, std::thread(&timeconsumingcode).detach();. On C++03 you should be able to model the same with the boost::thread.

bobah
  • 18,364
  • 2
  • 37
  • 70
2

You can use C Runtime Function _beginthreadex. You should change the signature of your timeconsumingcode a bit.

unsigned int __stdcall timeconsumingcode(void* pdata);
main()
{  
  _beginthreadex(NULL, 0, timeconsumingcode, NULL, 0, NULL);
  nextstep()
}

Please have look at MSDN - http://msdn.microsoft.com/en-us/library/kdzttdcb.aspx for more info