* [ECOS] select() and signal's
@ 2001-04-20 5:42 Boris V. Guzhov
2001-04-20 6:57 ` Jonathan Larmour
0 siblings, 1 reply; 7+ messages in thread
From: Boris V. Guzhov @ 2001-04-20 5:42 UTC (permalink / raw)
To: ecos-discuss
Hi,
Are there any way in eCos to interrupt the select() blocking
through a sending of a any signal?
For instance:
// posix thread 1:
void *thr1(void *par)
{
struct sigaction sa;
sigset_t mask;
sigemptyset( &mask );
sigaddset( &mask, SIGRTMIN );
pthread_sigmask( SIG_UNBLOCK, &mask, 0 );
sigemptyset( &sa.sa_mask );
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = my_sig_handler;
sigaction( SIGTRTMIN, &sa, NULL);
fd_set rfds;
int retval;
FD_ZERO(&rfds);
FD_SET(0, &rfds);
retval = select(1, &rfds, NULL, NULL, NULL);
if ( retval < 0 )
perror("select:");
...
}
// posix thread 2:
void *thr2(void *par)
{
...
pthread_kill( th1, SIGRTMIN) ;
...
}
In Linux it works, but in eCos it not works.
How can I do it in eCos?
Thanks in advance.
--
Boris Guzhov,
St.Petersburg, Russia
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ECOS] select() and signal's
2001-04-20 5:42 [ECOS] select() and signal's Boris V. Guzhov
@ 2001-04-20 6:57 ` Jonathan Larmour
2001-04-20 8:13 ` Boris V. Guzhov
0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Larmour @ 2001-04-20 6:57 UTC (permalink / raw)
To: Boris V. Guzhov; +Cc: ecos-discuss
"Boris V. Guzhov" wrote:
>
> Hi,
>
> Are there any way in eCos to interrupt the select() blocking
> through a sending of a any signal?
>
> For instance:
>
> // posix thread 1:
> void *thr1(void *par)
> {
> struct sigaction sa;
> sigset_t mask;
>
> sigemptyset( &mask );
> sigaddset( &mask, SIGRTMIN );
> pthread_sigmask( SIG_UNBLOCK, &mask, 0 );
>
> sigemptyset( &sa.sa_mask );
> sa.sa_flags = SA_SIGINFO;
> sa.sa_sigaction = my_sig_handler;
> sigaction( SIGTRTMIN, &sa, NULL);
>
> fd_set rfds;
> int retval;
>
> FD_ZERO(&rfds);
> FD_SET(0, &rfds);
> retval = select(1, &rfds, NULL, NULL, NULL);
> if ( retval < 0 )
> perror("select:");
> ...
> }
>
> // posix thread 2:
> void *thr2(void *par)
> {
> ...
> pthread_kill( th1, SIGRTMIN) ;
> ...
> }
>
> In Linux it works, but in eCos it not works.
It is meant to work in eCos. It's meant to return -1 and set errno to
EINTR. Are you sure thr1 isn't being pre-empted for any other reason, e.g.
if thr2 is higher priority.
Try setting a breakpoint on the function cyg_sigqueue and debugging it.
jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ECOS] select() and signal's
2001-04-20 6:57 ` Jonathan Larmour
@ 2001-04-20 8:13 ` Boris V. Guzhov
2001-04-20 13:11 ` Jonathan Larmour
0 siblings, 1 reply; 7+ messages in thread
From: Boris V. Guzhov @ 2001-04-20 8:13 UTC (permalink / raw)
To: ecos-discuss
But it still not works.
Both threads have an equal priority.
I carefully has looked on cyg_sigqueue() code.
And I don't understand as cyg_sigqueue() function will wake
the blocked in select() thread.
The cyg_sigqueue() function calls only signal_sigwait.broadcast().
But the blocked thread sleeps on other condition variable - selwait,
but not on signal_sigwait.
Thanks in advance.
--
Boris Guzhov,
St.Petersburg, Russia
> > In Linux it works, but in eCos it not works.
>
> It is meant to work in eCos. It's meant to return -1 and set errno to
> EINTR. Are you sure thr1 isn't being pre-empted for any other reason, e.g.
> if thr2 is higher priority.
>
> Try setting a breakpoint on the function cyg_sigqueue and debugging it.
>
> jifl
> --
> Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
> Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ECOS] select() and signal's
2001-04-20 8:13 ` Boris V. Guzhov
@ 2001-04-20 13:11 ` Jonathan Larmour
2001-04-21 5:52 ` Boris V. Guzhov
2001-04-21 6:02 ` Boris V. Guzhov
0 siblings, 2 replies; 7+ messages in thread
From: Jonathan Larmour @ 2001-04-20 13:11 UTC (permalink / raw)
To: Boris V. Guzhov; +Cc: ecos-discuss
"Boris V. Guzhov" wrote:
>
> But it still not works.
> Both threads have an equal priority.
> I carefully has looked on cyg_sigqueue() code.
> And I don't understand as cyg_sigqueue() function will wake
> the blocked in select() thread.
> The cyg_sigqueue() function calls only signal_sigwait.broadcast().
> But the blocked thread sleeps on other condition variable - selwait,
> but not on signal_sigwait.
Try the attached patch and let me know how you get on. I've only done some
simple tests. But I want you to try it with your existing code rather than
me spending more time on it[1]. *Do* let me know the outcome.
Jifl
[1] Since you're not a customer :)
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
? foo
Index: signal.cxx
===================================================================
RCS file: /home/cvs/ecc/ecc/compat/posix/current/src/signal.cxx,v
retrieving revision 1.11
diff -u -5 -p -r1.11 signal.cxx
--- signal.cxx 2001/02/14 01:25:44 1.11
+++ signal.cxx 2001/04/20 20:08:54
@@ -61,12 +61,13 @@
#include <signal.h> // our header
#include <setjmp.h>
#include <unistd.h> // _exit
#include <cyg/kernel/clock.hxx>
-
+#include <cyg/kernel/thread.hxx>
#include <cyg/kernel/clock.inl>
+#include <cyg/kernel/thread.inl>
// -------------------------------------------------------------------------
// Internal definitions
// Handle entry to a signal package function.
@@ -239,16 +240,33 @@ cyg_bool cyg_sigqueue( const struct sige
ss->pending = si;
}
// else A non-queuable signal, just set it pending
if( thread != NULL )
+ {
sigaddset( &thread->sigpending, signo );
- else sigaddset( &sig_pending, signo );
+ // just wake the thread up now if it's blocked somewhere
+ if ((thread->sigpending & ~thread->sigmask) != 0)
+ {
+ thread->thread->set_asr_pending();
+ thread->thread->release();
+ }
+ }
+ else
+ {
+ 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 );
+ }
+ }
- // Wake up any threads in sigsuspend() and sigwait().
- signal_sigwait.broadcast();
-
if( !locked ) signal_mutex.unlock();
return true;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ECOS] select() and signal's
2001-04-20 13:11 ` Jonathan Larmour
@ 2001-04-21 5:52 ` Boris V. Guzhov
2001-04-21 6:02 ` Boris V. Guzhov
1 sibling, 0 replies; 7+ messages in thread
From: Boris V. Guzhov @ 2001-04-21 5:52 UTC (permalink / raw)
To: Jonathan Larmour; +Cc: ecos-discuss
I tried this patch. And it works. But there are some questions.
Now pthread_kill() interrupts not only select() function
but also sem_wait().
As far as I know, semaphores are a general synchronization mechanism and
they can be used with a signal-cathing function (in particular, semaphores
can be posted from a POSIX signal-catching function). For instance, in
Linux pthread_kill() don't interrupts sem_wait().
> Try the attached patch and let me know how you get on. I've only done some
> simple tests. But I want you to try it with your existing code rather than
> me spending more time on it[1]. *Do* let me know the outcome.
>
> Jifl
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ECOS] select() and signal's
2001-04-20 13:11 ` Jonathan Larmour
2001-04-21 5:52 ` Boris V. Guzhov
@ 2001-04-21 6:02 ` Boris V. Guzhov
2001-04-23 12:32 ` Jonathan Larmour
1 sibling, 1 reply; 7+ messages in thread
From: Boris V. Guzhov @ 2001-04-21 6:02 UTC (permalink / raw)
To: Jonathan Larmour; +Cc: ecos-discuss
I tried and it works. But there are some questions.
Now pthread_kill() interrupts not only select(), but
also sem_wait().
As far as I know, the POSIX semaphores are a general and
exclusive synchronization mechanism with a signal-cathing
function. And their functions should not be interrupted by
signals.
In Linux inplementation pthread_kill() not interrupts
the sem_wait().
That's right?
--
Boris Guzhov,
St.Petersburg, Russia
> "Boris V. Guzhov" wrote:
> >
> > But it still not works.
> > Both threads have an equal priority.
> > I carefully has looked on cyg_sigqueue() code.
> > And I don't understand as cyg_sigqueue() function will wake
> > the blocked in select() thread.
> > The cyg_sigqueue() function calls only signal_sigwait.broadcast().
> > But the blocked thread sleeps on other condition variable - selwait,
> > but not on signal_sigwait.
>
> Try the attached patch and let me know how you get on. I've only done some
> simple tests. But I want you to try it with your existing code rather than
> me spending more time on it[1]. *Do* let me know the outcome.
>
> Jifl
>
> [1] Since you're not a customer :)
> --
> Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
> Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
----------------------------------------------------------------------------
----
> ? foo
> Index: signal.cxx
> ===================================================================
> RCS file: /home/cvs/ecc/ecc/compat/posix/current/src/signal.cxx,v
> retrieving revision 1.11
> diff -u -5 -p -r1.11 signal.cxx
> --- signal.cxx 2001/02/14 01:25:44 1.11
> +++ signal.cxx 2001/04/20 20:08:54
> @@ -61,12 +61,13 @@
> #include <signal.h> // our header
> #include <setjmp.h>
> #include <unistd.h> // _exit
>
> #include <cyg/kernel/clock.hxx>
> -
> +#include <cyg/kernel/thread.hxx>
> #include <cyg/kernel/clock.inl>
> +#include <cyg/kernel/thread.inl>
>
>
// -------------------------------------------------------------------------
> // Internal definitions
>
> // Handle entry to a signal package function.
> @@ -239,16 +240,33 @@ cyg_bool cyg_sigqueue( const struct sige
> ss->pending = si;
> }
> // else A non-queuable signal, just set it pending
>
> if( thread != NULL )
> + {
> sigaddset( &thread->sigpending, signo );
> - else sigaddset( &sig_pending, signo );
> + // just wake the thread up now if it's blocked somewhere
> + if ((thread->sigpending & ~thread->sigmask) != 0)
> + {
> + thread->thread->set_asr_pending();
> + thread->thread->release();
> + }
> + }
> + else
> + {
> + 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 );
> + }
> + }
>
> - // Wake up any threads in sigsuspend() and sigwait().
> - signal_sigwait.broadcast();
> -
> if( !locked ) signal_mutex.unlock();
>
> return true;
> }
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ECOS] select() and signal's
2001-04-21 6:02 ` Boris V. Guzhov
@ 2001-04-23 12:32 ` Jonathan Larmour
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Larmour @ 2001-04-23 12:32 UTC (permalink / raw)
To: Boris V. Guzhov; +Cc: ecos-discuss
"Boris V. Guzhov" wrote:
>
> I tried and it works. But there are some questions.
> Now pthread_kill() interrupts not only select(), but
> also sem_wait().
> As far as I know, the POSIX semaphores are a general and
> exclusive synchronization mechanism with a signal-cathing
> function. And their functions should not be interrupted by
> signals.
> In Linux inplementation pthread_kill() not interrupts
> the sem_wait().
>
> That's right?
My POSIX spec says explicitly "The sem_wait() function shall be
interruptible by the delivery of a signal." So if signals on Linux never
interrupt it, it sounds like Linux is wrong(!)
On doing so, sem_wait should return -1 and set errno to EINTR.
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2001-04-23 12:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-20 5:42 [ECOS] select() and signal's Boris V. Guzhov
2001-04-20 6:57 ` Jonathan Larmour
2001-04-20 8:13 ` Boris V. Guzhov
2001-04-20 13:11 ` Jonathan Larmour
2001-04-21 5:52 ` Boris V. Guzhov
2001-04-21 6:02 ` Boris V. Guzhov
2001-04-23 12:32 ` Jonathan Larmour
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).