+ Reply to Thread
Results 1 to 2 of 2

Thread: Can someone explain how to write a threading application using boost::thread?

  1. #1

    Can someone explain how to write a threading application using boost::thread?

    I want to use boost::thread in my application and want to know little bit about it.

    Can someone explain how to write a threading application using boost::thread?

    Simple example would do using VC++.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    23
    Below program is VC++ console based application using VS 2005:

    Code:
    #include <boost/thread.hpp>
    
    void MyThreadFun()
    {
    	std::cout << "ThreadFun\n" ;
    }
    
    int _tmain()
    {
    	boost::thread myThread1 = boost::thread(MyThreadFun) ;
    
    	boost::this_thread::sleep(boost::posix_time::milliseconds(1000)) ;
    
    	boost::thread myThread2 = boost::thread(MyThreadFun) ;
    
    	boost::this_thread::sleep(boost::posix_time::milliseconds(1000)) ;
    
    	return 0 ;
    }
    Note:
    You will need to make project setting to compile using multi-thread library.
    Project->Properties->Configuration Properties->C/C++->Code Generation->Runtime Library->Multi-threaded Debug (/MTd) or Multi-threaded (/MT).

    Hope this helps.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts