stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <Far...@kyiv.vdiweb.com>
Subject RE: string methods thread safety
Date Mon, 17 Jul 2006 16:10:06 GMT
 

> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Friday, July 07, 2006 4:20 AM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: string methods thread safety
> 
> 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);
> 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?

  I think the next_arg should be equal to the i-th element from array
thr_arg,
but thr_arg + i is address of the i-th element of the array thr_arg.

  If 0xa, 0xb, 0xc, x0d from your test are the parameters for the
thr_func() then
why thr_func() do receive the addresses of the memory with values 0xa,
...
instead of exactly values 0xa, ...? :)

  In the test below correct output does the first thread only (prints
"str1") and
this result depends from OS, CPU power etc.

----------------------------------------------------------------------
#include <rwthread.h>
#include <stdio.h>

rw_thread_t thr_id [4];
static const unsigned nthrs = sizeof thr_id / sizeof *thr_id;

char* str1 = "str1";
char* str2 = "str2";
char* str3 = "str3";
char* str4 = "str4";

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

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

    return *parg;
}

void run_test ()
{
    void* thr_arg[] = { str1, str2, str3, str4 };
    rw_thread_pool (thr_id, nthrs, 0, thr_func, thr_arg);
}

void print_result ()
{
    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 ()
{
    run_test ();
    print_result ();
}
----------------------------------------------------------------------
0012FEC4, 0040E11C, str1
thread 0 result = 0040E11C
0012FECC, 00000000, (null)
0012FEC8, 00000000, (null)
0012FEC8, 00000000, (null)
0012FED0, 00000000, (null)
thread 1 result = 00000000
thread 2 result = 00000000
thread 3 result = 00000000
----------------------------------------------------------------------

Farid.

Mime
View raw message