https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105030

--- Comment #5 from HaoChen Gui <guihaoc at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> something like
> 
> void *bar (void *x)
> {
>   *(double *)x = 1.;
> }
> 
> void foo(int n)
> {
>    double atemp;
>    pthread_create (..., bar, &atemp);
>    for (int i = 0; i < n; i++)
>      if (a[i] < atemp)
>        atemp = a[i];
>    pthread_join (...);
>    if (atemp != 1.)
>      abort ();
> }
> 
> if it is ensured the store to atemp in the loop never takes place then
> we have created a store data race when applying store motion.  Of course
> thread creation/join can be hidden in other functions called from foo()
> as long as 'atemp' escapes to callers.

I got it. Thanks a lot.
In the original case, the bar is called after the loop. So we still think the
atemp is safe for multi-threaded, as atemp can't be changed by others threads?
If the bar is executed before the loop, it's unsafe. Could we check all blocks
dominated by the loop head to find out the reference used in a call?

Reply via email to