Nikolsky Oleg(deleted)
|
3 questions to expirienced users
|
Nikolsky Oleg(deleted)
11/21/2008 5:42 AM
post17042
|
3 questions to expirienced users
3 questions to experienced QNX developers and users.
At unsophisticated user's first glance QNX 6.4.0 has many advantages as
compared with QNX previous versions. However, some unfortunate shortcomings
was inheretied from QNX 6.3.*.
///////////////////////////////////////////////////////////////////////////
1) Vagueness with valid limits of ualarm() function arguments.
Example program in HELP includes line of code with 10 seconds argument
/*ualarm((useconds_t)(10*1000*1000),0);*/. In fact function ualarm() can't
realize large time intervals. Below is simple program and its rezults.
=========================================================================
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#define BILLION 1000000000L;
//-----------------------------------------------------------------------
main(int argc, char **argv)
{
sigset_t set;
siginfo_t info;
struct timespec start, stop;
double accum;
int first_alarm = atoi(argv[1]);
int subsequent_alarms = atoi(argv[2]);
int i;
printf("Process with pid %d started\n", getpid());
sigemptyset(&set);
sigaddset(&set, SIGALRM);
printf("First_alarm time=%d s, subsequent_alarms period=%d s\n",
first_alarm, subsequent_alarms);
ualarm((useconds_t) (first_alarm * 1000 * 1000), (useconds_t)
(subsequent_alarms * 1000 * 1000));
for(i=0; i<10; i++)
{
clock_gettime( CLOCK_REALTIME, &start);
sigwaitinfo(&set, &info);
clock_gettime( CLOCK_REALTIME, &stop);
accum = (stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec -
start.tv_nsec) / (double)BILLION;
printf("Received signal %d with code %d. Time elapsed %lf\n",
info.si_signo, info.si_value, accum);
}
}
/*
# qcc -oualarm_glitch2.out ualarm_glitch2.c
# ./ualarm_glitch2.out 15 2
Process with pid 753706 started
First_alarm time=15 s, subsequent_alarms period=2 s
Received signal 14 with code 0. Time elapsed 2.116676 // was set to 15 s ????
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 2.000694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 2.000694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 2.000694
#
# ./ualarm_glitch2.out 250 2
Process with pid 778282 started
First_alarm time=250 s, subsequent_alarms period=2 s
Received signal 14 with code 0. Time elapsed 0.893863 // was set to 250 s ????
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 2.000694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 2.000694
Received signal 14 with code 0. Time elapsed 1.999694
Received signal 14 with code 0. Time elapsed 1.999694
#
*/
=========================================================================
If it is a bug in function ualarm() code, it must be corrected. Otherwise it
is desirable correct HELP documentaion similar to HELP on usleep() function
/*useconds The number of microseconds that you want to process to sleep for.
This must be less than 1,000,000.*/
/////////////////////////////////////////////////////////////////////////////
2) Erroneous rezults of bc utility with some sets of data. For example:
#...
View Full Message
|
|
|
Thomas Haupt
|
AW: 3 questions to expirienced users
|
Thomas Haupt
11/21/2008 7:56 AM
post17048
|
AW: 3 questions to expirienced users
Hi Nikolsky,
I had a look at what bc is doing there...
Looks like some bug between the modulo implementation
and bc's large-number representation.
I found these here:
971521081040539750285714285714285714 % 1234749221
624979906
(971521081040539750285714285714285714+1) % 1234749221
1414285714285714286339265621
985556825264819799999999999999999999 % 1234749221
14142857142857142857144091892077
(985556825264819799999999999999999999+1) % 1234749221
0
985556825264819799999999999999999999 /1234749221
798183799999999999999999999
(985556825264819799999999999999999999+1) /1234749221
798183800000000000000000000
Maybe that'll inspire you to look for a few more test-cases... ;-)
- Thomas
> -----Ursprüngliche Nachricht-----
> Von: Nikolsky Oleg [mailto:community-noreply@qnx.com]
> Gesendet: 21 November 2008 11:42
> An: momenticsgs-community
> Betreff: 3 questions to expirienced users
>
>
> 3 questions to experienced QNX developers and users.
>
> At unsophisticated user's first glance QNX 6.4.0 has many
> advantages as
> compared with QNX previous versions. However, some
> unfortunate shortcomings
> was inheretied from QNX 6.3.*.
>
> //////////////////////////////////////////////////////////////
> /////////////
> 1) Vagueness with valid limits of ualarm() function arguments.
> Example program in HELP includes line of code with 10 seconds
> argument
> /*ualarm((useconds_t)(10*1000*1000),0);*/. In fact function
> ualarm() can't
> realize large time intervals. Below is simple program and
> its rezults.
>
> ==============================================================
> ===========
> #include <stdio.h>
> #include <unistd.h>
> #include <stdlib.h>
> #include <signal.h>
> #include <time.h>
>
> #define BILLION 1000000000L;
> //------------------------------------------------------------
> -----------
> main(int argc, char **argv)
> {
> sigset_t set;
> siginfo_t info;
> struct timespec start, stop;
> double accum;
> int first_alarm = atoi(argv[1]);
> int subsequent_alarms = atoi(argv[2]);
> int i;
>
> printf("Process with pid %d started\n", getpid());
> sigemptyset(&set);
> sigaddset(&set, SIGALRM);
>
> printf("First_alarm time=%d s, subsequent_alarms period=%d s\n",
> first_alarm, subsequent_alarms);
> ualarm((useconds_t) (first_alarm * 1000 * 1000), (useconds_t)
> (subsequent_alarms * 1000 * 1000));
> for(i=0; i<10; i++)
> {
> clock_gettime( CLOCK_REALTIME, &start);
> sigwaitinfo(&set, &info);
> clock_gettime( CLOCK_REALTIME, &stop);
> accum = (stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec -
> start.tv_nsec) / (double)BILLION;
> printf("Received signal %d with code %d. Time elapsed %lf\n",
> info.si_signo, info.si_value, accum);
> }
> }
> /*
> # qcc -oualarm_glitch2.out ualarm_glitch2.c
> # ./ualarm_glitch2.out 15 2
> Process with pid 753706 started
> First_alarm time=15 s, subsequent_alarms period=2 s
> Received signal 14 with code 0. Time elapsed 2.116676 // was
> set to 15 s ????
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 2.000694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 2.000694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 2.000694
> #
>
> # ./ualarm_glitch2.out 250...
View Full Message
|
|
|
Thomas Haupt
|
AW: 3 questions to expirienced users
|
Thomas Haupt
11/21/2008 8:52 AM
post17053
|
AW: 3 questions to expirienced users
I did some more experiments with "bc":
11053%11054;
11053
11054%11054;
0
11055%11054;
1
11053%11055;
11053
11054%11055;
1991054
11055%11055;
0
11053%11056;
11053
11054%11056;
11054
11055%11056;
11055
And it's even worse. Here's a little bc program I wrote:
# cat bc.tst
for ( i = 2; i < 1000000; i++ ) {
j = ( i - 1 ) % i;
if ( j != ( i - 1 ) ) {
i;
}
}
# bc < bc.tst > bc.tst.out
# wc -l bc.tst.out
951800 bc.tst.out
That means that out of a million tested values, only 48200
will yield a correct result for (i-1)%i ...
- Thomas
> -----Ursprüngliche Nachricht-----
> Von: Nikolsky Oleg [mailto:community-noreply@qnx.com]
> Gesendet: 21 November 2008 11:42
> An: momenticsgs-community
> Betreff: 3 questions to expirienced users
>
>
> 3 questions to experienced QNX developers and users.
>
> At unsophisticated user's first glance QNX 6.4.0 has many
> advantages as
> compared with QNX previous versions. However, some
> unfortunate shortcomings
> was inheretied from QNX 6.3.*.
>
> //////////////////////////////////////////////////////////////
> /////////////
> 1) Vagueness with valid limits of ualarm() function arguments.
> Example program in HELP includes line of code with 10 seconds
> argument
> /*ualarm((useconds_t)(10*1000*1000),0);*/. In fact function
> ualarm() can't
> realize large time intervals. Below is simple program and
> its rezults.
>
> ==============================================================
> ===========
> #include <stdio.h>
> #include <unistd.h>
> #include <stdlib.h>
> #include <signal.h>
> #include <time.h>
>
> #define BILLION 1000000000L;
> //------------------------------------------------------------
> -----------
> main(int argc, char **argv)
> {
> sigset_t set;
> siginfo_t info;
> struct timespec start, stop;
> double accum;
> int first_alarm = atoi(argv[1]);
> int subsequent_alarms = atoi(argv[2]);
> int i;
>
> printf("Process with pid %d started\n", getpid());
> sigemptyset(&set);
> sigaddset(&set, SIGALRM);
>
> printf("First_alarm time=%d s, subsequent_alarms period=%d s\n",
> first_alarm, subsequent_alarms);
> ualarm((useconds_t) (first_alarm * 1000 * 1000), (useconds_t)
> (subsequent_alarms * 1000 * 1000));
> for(i=0; i<10; i++)
> {
> clock_gettime( CLOCK_REALTIME, &start);
> sigwaitinfo(&set, &info);
> clock_gettime( CLOCK_REALTIME, &stop);
> accum = (stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec -
> start.tv_nsec) / (double)BILLION;
> printf("Received signal %d with code %d. Time elapsed %lf\n",
> info.si_signo, info.si_value, accum);
> }
> }
> /*
> # qcc -oualarm_glitch2.out ualarm_glitch2.c
> # ./ualarm_glitch2.out 15 2
> Process with pid 753706 started
> First_alarm time=15 s, subsequent_alarms period=2 s
> Received signal 14 with code 0. Time elapsed 2.116676 // was
> set to 15 s ????
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 2.000694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 2.000694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 1.999694
> Received signal 14 with code 0. Time elapsed 2.000694
> #
>
> # ./ualarm_glitch2.out 250 2
> Process with pid 778282 started
> First_alarm time=250 s, ...
View Full Message
|
|
|
Sean Boudreau(deleted)
|
Re: 3 questions to expirienced users
|
Sean Boudreau(deleted)
11/21/2008 9:07 AM
post17054
|
Re: 3 questions to expirienced users
>
> That means that out of a million tested values, only 48200
> will yield a correct result for (i-1)%i ...
Please make a PR.
-seanb
|
|
|
Thomas Haupt
|
AW: 3 questions to expirienced users
|
Thomas Haupt
11/21/2008 9:27 AM
post17065
|
AW: 3 questions to expirienced users
PR# 63181
> -----Ursprungliche Nachricht-----
> Von: Sean Boudreau [mailto:community-noreply@qnx.com]
> Gesendet: 21 November 2008 15:07
> An: momenticsgs-community
> Betreff: Re: 3 questions to expirienced users
>
>
> >
> > That means that out of a million tested values, only 48200
> > will yield a correct result for (i-1)%i ...
>
> Please make a PR.
>
> -seanb
>
> _______________________________________________
> QNX Momentics Getting Started
> http://community.qnx.com/sf/go/post17054
>
>
|
|
|
Nikolsky Oleg(deleted)
|
Re: 3 questions to expirienced users
|
Nikolsky Oleg(deleted)
11/21/2008 9:29 AM
post17067
|
Re: 3 questions to expirienced users
Sean Boudreau, I have no expirience with making PR . Please prompt me how can do it?
O.Nikolsky
|
|
|
Thomas Haupt
|
AW: 3 questions to expirienced users
|
Thomas Haupt
11/21/2008 9:29 AM
post17068
|
AW: 3 questions to expirienced users
Oleg,
never mind - he was talking to me...
- Thomas
> -----Ursprungliche Nachricht-----
> Von: Nikolsky Oleg [mailto:community-noreply@qnx.com]
> Gesendet: 21 November 2008 15:29
> An: momenticsgs-community
> Betreff: Re: 3 questions to expirienced users
>
>
> Sean Boudreau, I have no expirience with making PR . Please
> prompt me how can do it?
> O.Nikolsky
>
> _______________________________________________
> QNX Momentics Getting Started
> http://community.qnx.com/sf/go/post17067
>
>
|
|
|
Nikolsky Oleg(deleted)
|
Re: AW: 3 questions to expirienced users
|
Nikolsky Oleg(deleted)
11/21/2008 9:25 AM
post17063
|
Re: AW: 3 questions to expirienced users
Thomas Haupt, Thank You for detailed analysis of bc utility rezults. It promisies that it will work fine after
correction.
O. Nikolsky
|
|
|
Thomas Haupt
|
AW: AW: 3 questions to expirienced users
|
Thomas Haupt
11/25/2008 10:21 AM
post17270
|
AW: AW: 3 questions to expirienced users
Hi,
I found the bug and provided a fix suggestion with the PR;
hope we can get a code inspection soon so I can check it in.
What I wasn't really aware of (and think is worth keeping in
mind) is that bc's "%" operator is _not_ a modulo operator;
instead it will yield the remainder after division over the
current maximum precision (scale). I.e., for scale = 0 the
% operation will in fact be modulo, but for scale > 0, the
results may look pretty bothering, e.g.:
10000%10001
10000 // correct
scale=2
10000%10001
99.01 // ???
10000/10001
.99
10001*.99
9900.99
10000-9900.99
99.01 // Ah!
This can be especially nasty when you invoke "bc -l", because
the standard bclib will set scale=20 , thus making % anything
but modulo...
Out of pure curiosity: Where did you get those numbers from?
Oh, while browsing the source I stumbled across another bug that
has quite some potential, too:
a=-3
b=5
a+b
2 // Ok
a+b
-2 // ???
a
3 // ?????
b
-5 // ?????
In other words, if you add two variables of which the first one
holds a negative and the second one a positive value, then the signs
of these two variables will be swapped...
This one has been filed as PR #63216 and a fix is also suggested.
Thanks again for pointing at the original issue,
- Thomas
> -----Ursprungliche Nachricht-----
> Von: Nikolsky Oleg [mailto:community-noreply@qnx.com]
> Gesendet: 21 November 2008 15:26
> An: momenticsgs-community
> Betreff: Re: AW: 3 questions to expirienced users
>
>
> Thomas Haupt, Thank You for detailed analysis of bc utility
> rezults. It promisies that it will work fine after correction.
> O. Nikolsky
>
> _______________________________________________
> QNX Momentics Getting Started
> http://community.qnx.com/sf/go/post17063
>
>
|
|
|
Nikolsky Oleg(deleted)
|
Re: AW: AW: 3 questions to expirienced users
|
Nikolsky Oleg(deleted)
11/25/2008 3:05 PM
post17305
|
Re: AW: AW: 3 questions to expirienced users
Hi Thomas,
The numbers led to erronemous calculations with bc utility I met in one of example programs for my students (look at
document #4 at qnx-student.narod.ru web
page). That program among other things illustrated usage of bc together with pipes for RSA-encryption using big prime
numbers.
While working with program I met much more erronemous bc results, particularly bc was unable to read commands from file.
Undoubtedly, description of bc
utitlity in QNX help system also was insufficient.
Please can you clarify where and how QNX users will be notified of patched bc?
I am sorry for one more question (not reffered to bc), but can you say something about function ualarm() arguments'
limits (my first question in the original
post)? sizeof(useconds_t) = 4, so I can expect limits from 0 seconds to (2^(4*8))/1000000 = 4294 seconds. However as
shown in program in the initial post,
ualarm() can't realize correctly big time intervals.
Oleg.
|
|
|
Thomas Haupt
|
AW: AW: AW: 3 questions to expirienced users
|
Thomas Haupt
11/26/2008 5:57 AM
post17342
|
AW: AW: AW: 3 questions to expirienced users
Hi Oleg,
users aren't notified of changes, but as you can see in
the trunk's svn log message for revision 207257, the fix
is already reflected on the public repository. You can
check out utils/b/bc and build the fixed utility yourself.
About document #4 - I'll just have to believe you on that
part, as I have to admit that my knowledge of Cyrillic
letters is close to and that of the Russian language about
equal to zero...
I already thought this would have something to do with
encryption - somehow the number looked like it... ;-)
Regarding bc not being able to read command files - I really
cannot reproduce that problem here. If I prepare a command
file, e.g., "bc.in" and do
bc bc.in
then all commands from bc.in are executed and bc waits for
more input from stdin, and if I do
bc < bc.in
then all commands are executed and bc terminates.
The behavior you described for ualarm() is in fact a tiny
bug; the values are internally scaled to nanoseconds and
passed around as _Uint64t. Unfortunately, the multiplication
with 1000 (to get nano- from microseconds) still happens on
_Uint32t, so that every <usec> or <interval> argument above
(2^32-1)/1000 (i.e., 4294967) will overflow.
I created PR #63312 for this and provided a fix suggestion;
if all goes well, it could get submitted within days.
- Thomas
> can you say something about function ualarm() arguments'
> limits (my first question in the original
>
> post)? sizeof(useconds_t) = 4, so I can expect limits from 0
> seconds to (2^(4*8))/1000000 = 4294 seconds. However as shown
> in program in the initial post,
>
> ualarm() can't realize correctly big time intervals.
> -----Ursprungliche Nachricht-----
> Von: Nikolsky Oleg [mailto:community-noreply@qnx.com]
> Gesendet: 25 November 2008 21:06
> An: momenticsgs-community
> Betreff: Re: AW: AW: 3 questions to expirienced users
>
>
> Hi Thomas,
>
> The numbers led to erronemous calculations with bc utility I
> met in one of example programs for my students (look at
> document #4 at qnx-student.narod.ru web
>
> page). That program among other things illustrated usage of
> bc together with pipes for RSA-encryption using big prime numbers.
> While working with program I met much more erronemous bc
> results, particularly bc was unable to read commands from
> file. Undoubtedly, description of bc
>
> utitlity in QNX help system also was insufficient.
>
> Please can you clarify where and how QNX users will be
> notified of patched bc?
>
> I am sorry for one more question (not reffered to bc), but
> can you say something about function ualarm() arguments'
> limits (my first question in the original
>
> post)? sizeof(useconds_t) = 4, so I can expect limits from 0
> seconds to (2^(4*8))/1000000 = 4294 seconds. However as shown
> in program in the initial post,
>
> ualarm() can't realize correctly big time intervals.
>
> Oleg.
>
> _______________________________________________
> QNX Momentics Getting Started
> http://community.qnx.com/sf/go/post17305
>
>
|
|
|
Nikolsky Oleg(deleted)
|
Re: AW: AW: AW: 3 questions to expirienced users
|
Nikolsky Oleg(deleted)
11/26/2008 8:18 AM
post17350
|
Re: AW: AW: AW: 3 questions to expirienced users
Thomas,
Thank you very much for pithy reply.
Oleg
|
|
|
|