public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] sigwait not returning
@ 2003-01-29 18:09 N.Suresh
  2003-01-29 23:33 ` Nick Garnett
  0 siblings, 1 reply; 6+ messages in thread
From: N.Suresh @ 2003-01-29 18:09 UTC (permalink / raw)
  To: ecos-discuss; +Cc: Shiv Kumar, Prakash R, Titty Thomas

Hi all,
    I am using sigwait () call to handle the signal in a thread.
    But the call never returns.

    We have traced the call and found that the thread is exiting in 
cyg_deliver_signals function with
    error "Unknown handler for the signal".

    I think it shouldn't enter the function at all, because the delivery 
method for
    sigwait call is via the broadcast method for the global  condition 
variable named signal_sigwait.
   
    I have attached the example code below.
    Am i missing something?

thanx in advance,
regards

<cut>

#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <cyg/infra/diag.h>

main ()
{
	int ret_val;
	sigset_t set;
	int sig;

	// Unblock all the signals
	sigfillset (&set);
	pthread_sigmask (SIG_UNBLOCK, &set, (sigset_t*)NULL);

	//--------------------------------------------------------------------
	// <start of timer initialization section>
	//--------------------------------------------------------------------
	struct itimerspec timerValue;	// Timeout value on eCos
	timer_t timer1;			// Timer
	struct sigevent sev;
	
	// Notification type --- Deliver the signal
	sev.sigev_notify                = SIGEV_SIGNAL;
	sev.sigev_signo                 = SIGALRM;
	sev.sigev_value.sival_int       = 0xABCDEF01;
	
	// Timer values	--- 1 Second
	timerValue.it_value.tv_sec           = 1;
	timerValue.it_value.tv_nsec          = 0;
	timerValue.it_interval.tv_sec        = 0;
	timerValue.it_interval.tv_nsec       = 0;
	
	if (timer_create (CLOCK_REALTIME, &sev, &timer1) != 0)
		diag_printf ("Error in creating the timer\n");

	if (timer_settime (timer1, 0, &timerValue, NULL ) !=0)
		diag_printf ("Error in setting the time\n");

	//--------------------------------------------------------------------
	// <end of timer initialization section>
	//--------------------------------------------------------------------

	diag_printf ("Timer initialisation is completed..\n");

	// Wait for any signal to arrive
	sigfillset (&set);
	ret_val = sigwait (&set, &sig);

	if (ret_val ==0)
	{
		diag_printf ("The signal number %d received\n", sig);
	}
	else
		diag_printf ("Error in sigwait call\n");

	diag_printf ("Program terminating\n");
	exit (0);
}

</cut>

-- 
!============================================================================!
= Suresh N., Research Engineer, C-DoT, Bangalore.        		     =
= Call me at : OFF: 2383951(Dir) / 2263399 (268)  RES: 3334248               =
= Alternate email :  nsur_mys@rediffmail.com				     =
= QOT: Modern man is the missing link between apes and human beings.
!============================================================================!



-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] sigwait not returning
  2003-01-29 18:09 [ECOS] sigwait not returning N.Suresh
@ 2003-01-29 23:33 ` Nick Garnett
  2003-01-30  8:44   ` N.Suresh
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Garnett @ 2003-01-29 23:33 UTC (permalink / raw)
  To: N.Suresh; +Cc: ecos-discuss, Shiv Kumar, Prakash R, Titty Thomas

"N.Suresh" <nsuresh@cdotb.ernet.in> writes:

> Hi all,
>     I am using sigwait () call to handle the signal in a thread.
>     But the call never returns.
> 
>     We have traced the call and found that the thread is exiting in
> cyg_deliver_signals function with
>     error "Unknown handler for the signal".
> 
>     I think it shouldn't enter the function at all, because the
> delivery method for
>     sigwait call is via the broadcast method for the global  condition
> variable named signal_sigwait.
>      I have attached the example code below.
>     Am i missing something?

You are. For sigwait() to work you have to block the signals you are
sigwait()ing for from normal delivery. sigwait() then unblocks the
signals it wants, but stops them from being delivered via the normal
mechanism and delivers them by returning.

> 	// Unblock all the signals
> 	sigfillset (&set);
> 	pthread_sigmask (SIG_UNBLOCK, &set, (sigset_t*)NULL);

Try this instead:

	pthread_sigmask (SIG_BLOCK, &set, (sigset_t*)NULL);

-- 
Nick Garnett - eCos Kernel Architect
http://www.eCosCentric.com/


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] sigwait not returning
  2003-01-29 23:33 ` Nick Garnett
@ 2003-01-30  8:44   ` N.Suresh
  2003-01-30 17:46     ` N.Suresh
  0 siblings, 1 reply; 6+ messages in thread
From: N.Suresh @ 2003-01-30  8:44 UTC (permalink / raw)
  To: Nick Garnett; +Cc: ecos-discuss, Prakash R, Shiv Kumar, Titty Thomas

>
>
>Try this instead:
>
>	pthread_sigmask (SIG_BLOCK, &set, (sigset_t*)NULL);
>
>  
>
I had tried this before. It didn't work.
So i tried to unblock all the signals in the thread itself.

If i don't do this, in alarm_action () function, the check whether any 
thread is waiting for the signal is failing and
it is simply returning.

regards

-- 
!============================================================================!
= Suresh N., Research Engineer, C-DoT, Bangalore.        		     =
= Call me at : OFF: 2383951(Dir) / 2263399 (268)  RES: 3334248               =
= Alternate email :  nsur_mys@rediffmail.com				     =
= QOT: Modern man is the missing link between apes and human beings.
!============================================================================!




-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] sigwait not returning
  2003-01-30  8:44   ` N.Suresh
@ 2003-01-30 17:46     ` N.Suresh
  2003-01-31 14:29       ` Nick Garnett
  0 siblings, 1 reply; 6+ messages in thread
From: N.Suresh @ 2003-01-30 17:46 UTC (permalink / raw)
  To: N.Suresh; +Cc: Nick Garnett, ecos-discuss, Prakash R, Shiv Kumar, Titty Thomas

Hi,
    We tried delivering the signal to a sigwait () call:
        *) Using alarm () function --- Working.
        *) pthread_kill () function ---  Working.

    It looks like only in the case of timer_create () case, the sigwait 
is not returning.

    We traced the call and found that in the following piece of code, 
signal_sigwait condition variable's queue is empty.
    So it is not calling the broadcast method which will wake the 
sigwait thread.
    It is releasing the thread, and in next POSIX_ASR call, the 
cyg_deliver_signals function is calling  _exit because there
     is no signal handler registered for this thread.
   
     All these functions are getting called only if i unmask the signal 
in the thread before calling the sigwait.
     Otherwise the check in the alarm_action function whether thread is 
accepting this signal will fail.
   
    Are we on the right path of debugging?

regards

<cut signal.cxx>

     sigaddset( &sig_pending, signo );

        // Wake up any threads in sigsuspend() and sigwait().

        if (!signal_sigwait.get_queue()->empty())

        {

            signal_sigwait.broadcast();

        } 

        else

        {

            cyg_posix_pthread_release_thread( &sig_pending );

        }

</cut signal.cxx>

   

N.Suresh wrote:

>>
>>
>> Try this instead:
>>
>>     pthread_sigmask (SIG_BLOCK, &set, (sigset_t*)NULL);
>>
>>  
>>
> I had tried this before. It didn't work.
> So i tried to unblock all the signals in the thread itself.
>
> If i don't do this, in alarm_action () function, the check whether any 
> thread is waiting for the signal is failing and
> it is simply returning.
>
> regards
>


-- 
!============================================================================!
= Suresh N., Research Engineer, C-DoT, Bangalore.        		     =
= Call me at : OFF: 2383951(Dir) / 2263399 (268)  RES: 3334248               =
= Alternate email :  nsur_mys@rediffmail.com				     =
= QOT: Modern man is the missing link between apes and human beings.
!============================================================================!




-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] sigwait not returning
  2003-01-30 17:46     ` N.Suresh
@ 2003-01-31 14:29       ` Nick Garnett
  2003-01-31 18:36         ` Nick Garnett
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Garnett @ 2003-01-31 14:29 UTC (permalink / raw)
  To: N.Suresh; +Cc: ecos-discuss, Prakash R, Shiv Kumar, Titty Thomas

"N.Suresh" <nsuresh@cdotb.ernet.in> writes:

> Hi,
>     We tried delivering the signal to a sigwait () call:
>         *) Using alarm () function --- Working.
>         *) pthread_kill () function ---  Working.
> 
>     It looks like only in the case of timer_create () case, the
> sigwait is not returning.
> 
>     We traced the call and found that in the following piece of code,
> signal_sigwait condition variable's queue is empty.
>     So it is not calling the broadcast method which will wake the
> sigwait thread.
>     It is releasing the thread, and in next POSIX_ASR call, the
> cyg_deliver_signals function is calling  _exit because there
>      is no signal handler registered for this thread.
>       All these functions are getting called only if i unmask the
> signal in the thread before calling the sigwait.
>      Otherwise the check in the alarm_action function whether thread
> is accepting this signal will fail.
>      Are we on the right path of debugging?
> 

Sort of. I've been looking at this myself. The problem is that the
timer alarm_action() routine should broadcast the signal_sigwait
condition variable the same way that sigalrm_action() does.

I have this fixed locally. However, We've been having power cuts here
and I haven't had time to check it in to the repository. I'll try to
do that later today.


-- 
Nick Garnett - eCos Kernel Architect
http://www.eCosCentric.com/


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] sigwait not returning
  2003-01-31 14:29       ` Nick Garnett
@ 2003-01-31 18:36         ` Nick Garnett
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Garnett @ 2003-01-31 18:36 UTC (permalink / raw)
  To: N.Suresh; +Cc: ecos-discuss, Prakash R, Shiv Kumar, Titty Thomas

Nick Garnett <nickg@ecoscentric.com> writes:

> 
> I have this fixed locally. However, We've been having power cuts here
> and I haven't had time to check it in to the repository. I'll try to
> do that later today.

Now done. Update CVS to get it.

-- 
Nick Garnett - eCos Kernel Architect
http://www.eCosCentric.com/


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-01-31 18:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-29 18:09 [ECOS] sigwait not returning N.Suresh
2003-01-29 23:33 ` Nick Garnett
2003-01-30  8:44   ` N.Suresh
2003-01-30 17:46     ` N.Suresh
2003-01-31 14:29       ` Nick Garnett
2003-01-31 18:36         ` Nick Garnett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).