[omniORB] Threading problem on Win32

Vladislav Vrtunski vladislav.vrtunski at dmsgroup.co.yu
Sat Jan 28 16:04:03 GMT 2006


Robert Hanson wrote:
>
> Wrote this simple program to test omnithreads on Linux and win32 
> (xp);  it works just fine under linux; but the worker thread never 
> exits the wait call on win32. 
>
>  
>
> Can anyone see what I might be missing?
>
>  
>
> #include <stdio.h>       /* standard I/O routines                     */
>
> #include <stdlib.h>      /* rand() and srand() functions              */
>
> #include <omnithread.h>
>
>  
>
> omni_mutex mutex;
>
> omni_condition condition(&mutex);
>
>  
>
> void* handle_requests_loop(void* data)
>
> {
>
>     int thread_id = *((int*)data);  /* thread identifying 
> number           */
>
>     printf("Starting thread '%d'\n", thread_id);
>
>     fflush(stdout);
>
>  
>
>       printf("wait %d\n",thread_id);
>
>       fflush(stdout);
>
>       condition.wait();
>
>       printf("thread executing after wait %d\n",thread_id);
>
>       return(NULL);
>
>  }
>
>  
>
> int
>
> main(int argc, char* argv[])
>
> {
>
>     omni_thread *p_thread;
>
>       int id=1;
>
>  
>
>       p_thread = 
> omni_thread::create(handle_requests_loop,(void*)&id,omni_thread::PRIORITY_NORMAL);
>
>       printf("sleep before signal\n");
>
>       fflush(stdout);
>
>       omni_thread::sleep(1,10);
>
>       // ensure that the thread has performed the wait
>
>       condition.signal();
>
>       printf("done with signal\n");
>
>       fflush(stdout);
>
>       omni_thread::sleep(1,10);
>
>       printf("exit\n");
>
>       fflush(stdout);
>
> }
>
>  
>
Before you call condition.wait(), you must lock the mutex you associated 
with the omni_condition instance. So, locking mutex before calling wait 
on the condition object and unlocking it right after it will make your 
example program work.

Since, omnithread library is modeled to be POSIX like, you can read 
documentation on POSIX conditions (or POSIX threads in general) to 
understand the way conditions are supposed to work. Look into, for 
example, the man pages for pthread_cond_wait & pthread_cond_signal on 
your Linux system.

Regards,

-- 
*****************************************************
Vladislav Vrtunski
DMS Group
Puskinova 9a
21000 Novi Sad
Serbia & Montenegro

Phone: +381 21 4746008
vladislav.vrtunski at dmsgroup.co.yu
http://www.dmsgroup.co.yu/
***************************************************** 




More information about the omniORB-list mailing list