[omniORB]The omnithread problem and solution
Алексей Иваненко
aivanenko at mail.ru
Thu Nov 27 14:07:13 GMT 2008
Hello All. My name is Alexey and i have a question. Recently i came across some omnithread problem. I am developing an application which uses CORBA of course and about 179 omnithreads. But when my application makes 166 threads omni throw an exception omni_thread_fatal. I think that reason of this problem is fulfilled of stack. I've modified program code of omnithread library and it works. First of all i want to show my solution and ask why omniORB developers didn't make something like that? Maybe there were some problems, which i don't know. I've tested it and it worked fine. But maybe there will be situations where it will be cause of problems. If so i will be glad to know that.
I am using omniORB-4.0.5 (but i saw source cod of omniORB-4.1.2 where the same style of thread creation). My application works in Linux, so i have modified POSIX.cc (i attached it to this letter).
Main idea: When there isn't enough space in process address space to allocate mammary for thread stack, it will be allocated by using malloc() function.
Details:
************First i've added 2 variables
void * stack_ptr=0; <- stack pointer for a new thread
size_t stack_size_def = 32768; <- size of a new stack
************In start function i've made following canges:
if (PthreadDraftVersion == 4)
if (pthread_create(&posix_thread, &attr, omni_thread_wrapper,(void*)this)!=0) <-create until enough mammary if not enough stack space then
{
if (stack_size)
{
stack_ptr=malloc(stack_size); <-allocate mammary for new thread;
stack_size_def=stack_size;
{
else stack_ptr=malloc(stack_size_def);
if (stack_ptr)
{
THROW_ERRORS (pthread_attr_setstack(&attr,stack_ptr,stack_size_def));<-define where stack will be
THROW_ERRORS (pthread_create(&posix_thread, &attr, omni_thread_wrapper,(void*)this));<-and create thread
}
else throw omni_thread_fatal(errno);
}
pthread_attr_delete(&attr);
#else
if (pthread_create(&posix_thread, &attr, omni_thread_wrapper,(void*)this)!=0)
{
if (stack_size)
{
stack_ptr=malloc(stack_size);
stack_size_def=stack_size;
{
else stack_ptr=malloc(stack_size_def);
if (stack_ptr)
{
THROW_ERRORS (pthread_attr_setstack(&attr,stack_ptr,stack_size_def));
THROW_ERRORS (pthread_create(&posix_thread, &attr, omni_thread_wrapper,(void*)this));
}
else throw omni_thread_fatal(errno);
}
pthread_attr_destroy(&attr);
#endif
********** In exit function i've added:
if (stack_ptr) free(stack_ptr);
I'll be grateful if you'll answer me.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: posix.cc
Type: application/octet-stream
Size: 22502 bytes
Desc: not available
Url : http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20081127/5cd1a9cd/posix-0001.obj
More information about the omniORB-list
mailing list