On Wed, Sep 26, 2012 at 9:51 PM, Ted Unangst <t...@tedunangst.com> wrote:
> On Wed, Sep 26, 2012 at 11:18, Alexey Suslikov wrote:
>> Hi.
>>
>> Any news on that?
>
> Can we do it without the local variables for speed part?  I am not
> interested in making this function faster.
>

Removing only local variables part reverts us to previous
behavior (i.e. crashes).

However, leaving current code as is but adding only local
variables (see below) passes our test with no crashes.

I'm starting to believe that static globals are not good.

Can somebody help us with writing threaded test case?

As I mentioned above, we use Kannel port as a test which
is somewhat hard to share.

Alexey

Index: lib/libc/stdlib/random.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/random.c,v
retrieving revision 1.17
diff -u -p -r1.17 random.c
--- lib/libc/stdlib/random.c    1 Jun 2012 01:01:57 -0000       1.17
+++ lib/libc/stdlib/random.c    26 Sep 2012 20:30:46 -0000
@@ -380,17 +380,20 @@ long
 random(void)
 {
        int32_t i;
+       int32_t *f, *r;

        if (rand_type == TYPE_0)
                i = state[0] = (state[0] * 1103515245 + 12345) & 0x7fffffff;
        else {
-               *fptr += *rptr;
-               i = (*fptr >> 1) & 0x7fffffff;  /* chucking least random bit */
-               if (++fptr >= end_ptr) {
-                       fptr = state;
-                       ++rptr;
-               } else if (++rptr >= end_ptr)
-                       rptr = state;
+               f = fptr; r = rptr;
+               *f += *r;
+               i = (*f >> 1) & 0x7fffffff;     /* chucking least random bit */
+               if (++f >= end_ptr) {
+                       f = state;
+                       ++r;
+               } else if (++r >= end_ptr)
+                       r = state;
+               fptr = f; rptr = r;
        }
        return((long)i);
 }

Reply via email to