Unix Programming - sema_wait not return as expected

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > December 2005 > sema_wait not return as expected





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sema_wait not return as expected
hao

2005-12-31, 7:49 am

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!!!!

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com