Nikolai Gorbunov <n.gorbunov@swd.ru> wrote:
Hi Gurus,
Almost a philosophical question. Is Trigger() really a non-blocking call, or
just a ‘blocking and instantly unblocking’ one?
Um…define instantly unblocking? Yes, it makes a kernel call, no
your process doesn’t leave the READY state.
A typical scenario. There are two processes (A and B) at the same priority,
FIFO scheduling, both READY. A higher-priority process (C) is runniung. Then
the following happens:
- C goes blocked, A gets the CPU.
- In the middle of its timeslice, A calls Trigger().
Will A be still running after this? Assuming that Trigger() is ‘a kind of
Send() which returns immediately’, calling it should cause rescheduling
anyway, so after A calls Trigger(), B will instantly get the CPU.
Am I right?
A should continue running after the Trigger().
P.S. “This question is based on a real story.” >
My small test bears this out.
I set up a program that creates two proxies. Setup two fifo processes
that loop and occasionally Trigger their proxy – one is given proxya
the other proxyb.
When I run them, I see a few “proxy a”, then when I run the 2nd program,
I see one “proxy b”, the Trigger() before it drops its priority just
to make sure it got the right proxy, then I never see another Trigger from
proxy b – only proxy a.
So, this bears out that Trigger() doesn’t block, even instantly, the
calling process.
(Note: if running on a fast machine, may want to grow the length of the
delay loops, this was run on a 133Mhz Pentium.)
-David
recv.c:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/kernel.h>
#include <sys/proxy.h>
#include <sys/sched.h>
void main()
{
int proxya, proxyb, pid;
proxya = qnx_proxy_attach( 0, 0, 0, -1 );
proxyb = qnx_proxy_attach( 0, 0, 0, -1 );
printf(“proxya: %d, proxyb: %d\n”, proxya, proxyb );
while(1) {
pid = Receive(0, NULL, 0 );
if (pid == proxya) printf(“proxy from a\n”);
if (pid == proxyb) printf(“proxy from b\n”);
}
}
trigger.c:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/kernel.h>
#include <sys/proxy.h>
#include <sys/sched.h>
void main(int argc, char **argv)
{
int proxy;
struct sched_param param;
int i;
proxy = atoi( argv[1] );
Trigger(proxy );
param.sched_priority = 5;
sched_setscheduler( 0, SCHED_FIFO, ¶m );
//setprio( 0, 5 );
while(1) {
for(i=0; i<10000000; i++ );
Trigger(proxy);
}
printf(“i is %d\n”, i );
}
-David
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.