Jump to content
  • Advertisement

pnraj

Member
  • Content Count

    0
  • Joined

  • Last visited

Community Reputation

110 Neutral

About pnraj

  • Rank
    Newbie
  1. I benefited a lot from Drew's article. I am now stuck with a particular issue, not finding any clue any where. Can someone please help! Its like this. I wish to know if there is a way for a function being executed in a thread, to access values copied into the thread's structure.   Let me explain with the example 2e, modified by addition of an argument of an int. Boost doc tells me that "int x" will be copied into the thread's internal structure. Now, is there a way that a handler posted to the threadpool can access the value of "myThreadnum" of the particular thread where it gets to run?    In other words, is there a way in which a thread can hold values/objects in its internal structure, that can be accessed by runnables that land on the thread?   void WorkerThread( boost::asio::io_service & io_service, int x) { int myThreadNum = x;    int myThread-num = i;                     std::cout << "Thread Start\n"; io_service.run(); std::cout << "Thread Finish\n"; } int main(int argc, char **argv) { boost::asio::io_service io_service; boost::asio::io_service::work work(io_service); std::cout << "Press [return] to exit." << std::endl; boost::thread_group worker_threads; for( int x = 0; x < 4; ++x ) { worker_threads.create_thread( boost::bind( &WorkerThread, std::ref(io_service, x) ) ); } std::cin.get(); io_service.stop(); worker_threads.join_all(); return 0; }   Thanks a lot!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!