|
| I write a multi-thread program on solaris 8, as the follow:
// a.C
sema_t wait_sem;
int main()
{
sema_init(&wait_sem, 0, USYNC_THREAD, NULL);
// create one thread
create_thread();
sema_wait(&wait_sem)
}
//b.C
extern sem_t wait_sem
create_thread()
{
//call pthread_thread to create thread
// thread function is MainLoop
}
void* MainLoop(void* param)
{
while (noerror)
{
//handling something
}
sema_post(&wati_sem);
}
The problem is when error occurs in MainLoop, sema_post is called,
but
sema_wait don't return, as if the main thread wouldn't be re-awaken. I
make sure at that time the count of wait_sem is 1.
If I instert "sleep(60)" before sema_wait. During 60 seconds,
MainLoop call sema_post, then sema_wait is called after 60 seconds
expired. In this case,
sema_wait returns immediately.
Hope for a pointer or suggestion, Thanks!!!!
|
|