incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: string methods thread safety
Date Fri, 07 Jul 2006 01:20:11 GMT
Martin Sebor wrote:
> Anton Pevtsov wrote:
[...]
>> I found the tricky place in the rwthread.cpp, line 397:
>>     void* const next_arg = thr_arg ? thr_arg + i : (void*)(thr_id +
>> i);
>> I suspect here should be
>>     void* const next_arg = thr_arg ? *(thr_arg + i) : (void*)(thr_id
>> + i);
>> The fix included.
> 
> 
> Let me look into this tomorrow.

I put together a test to help me understand the problem (see
below) but I don't see anything wrong with its output. Do you?

(Btw., we should probably rename rwthread.h and rwthread.cpp
to rw_thread.h and thread.cpp for consistency with the rest of
the driver source files.)

Martin

$ cat v.cpp && nice make v && ./v
#include <rwthread.h>
#include <stdio.h>

void* thr_func (void *arg)
{
     void* const* const parg = (void**)arg;

     printf ("%p, %p\n", parg, *parg);

     return *parg;
}

void test (bool arg)
{
     rw_thread_t thr_id [4];
     static const unsigned nthrs = sizeof thr_id / sizeof *thr_id;

     void* thr_arg [nthrs] = { 0, 0, 0, 0 };
     if (arg) {
         thr_arg [0] = (void*)0xa;
         thr_arg [1] = (void*)0xb;
         thr_arg [2] = (void*)0xc;
         thr_arg [3] = (void*)0xd;
     };

     printf ("invoking rw_thread_pool() with a %snull thread argument\n",
             arg ? "non-" : "");

     rw_thread_pool (thr_id, nthrs, 0, thr_func, arg ? thr_arg : 0);

     void* thr_res [nthrs] = { 0, 0, 0, 0 };

     for (unsigned i = 0; i != nthrs; ++i) {
         rw_thread_join (thr_id [i], thr_res + i);
         printf ("thread %u result = %p\n", i, thr_res [i]);
     }
}

int main ()
{
     test (false);
     test (true);
}
gcc -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG   -pthreads 
-D_RWSTD_USE_CONFIG -I/build/sebor/dev/stdlib/include 
-I/build/sebor/gcc-4.1.0-15s/include -I/build/sebor/dev/stdlib/../rwtest 
-I/build/sebor/dev/stdlib/../rwtest/include 
-I/build/sebor/dev/stdlib/tests/include  -pedantic -nostdinc++ -g  -W 
-Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings -Wno-long-long  v.cpp
v.cpp: In function 'void* thr_func(void*)':
v.cpp:8: warning: format '%p' expects type 'void*', but argument 2 has 
type 'void* const*'
gcc v.o -o v -L/build/sebor/gcc-4.1.0-15s/rwtest -lrwtest15s -pthreads 
-L/build/sebor/gcc-4.1.0-15s/lib -lstd15s  -lsupc++ -lm
invoking rw_thread_pool() with a null thread argument
ffbffa48, 0
ffbffa54, 1
ffbffa6c, 3
ffbffa60, 2
thread 0 result = 0
thread 1 result = 1
thread 2 result = 2
thread 3 result = 3
invoking rw_thread_pool() with a non-null thread argument
ffbffa88, a
ffbffa90, c
ffbffa8c, b
thread 0 result = a
thread 1 result = b
thread 2 result = c
ffbffa94, d
thread 3 result = d

Mime
View raw message