
Alapkumar Sinha <Alapkumar.Sinha@lntinfotech.com> writes:
I have modified the code as below. Can someone tell me if this changes are fine or not?
void thread::start_thread() { thread_info->self=thread_info; // [AKS] Addded code to set the stack size to 2 MB size_t mystacksize; pthread_attr_init(&attr1); //attr1 is a global variable mystacksize =2097152; pthread_attr_setstacksize (&attr1, mystacksize); //[AKS] End of change
int const res = pthread_create(&thread_info->thread_handle, &attr1, &thread_proxy, thread_info.get()); if (res != 0) { thread_info->self.reset(); boost::throw_exception(thread_resource_error()); }
}
It looks OK apart from the "attr1 is a global variable" part. That would introduce a race condition in starting threads. Don't do that, just make it local, or initialize it once (e.g. with call_once). Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976