octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Switch to std::atomic?


From: Rik
Subject: Re: Switch to std::atomic?
Date: Thu, 26 Sep 2019 18:53:59 -0700

On 09/26/2019 02:43 PM, John W. Eaton wrote:
> On 9/26/19 5:18 PM, Rik wrote:
>
>> Was there a particular reason to make oct-atomic.c a 'C' language file
>> rather than a C++ file?  If possible, it would seem better to make this C++
>> and possible also add an 'inline' declaration so that we don't get function
>> call overhead.
>
> To try to inline the calls to the atomic_fetch_add and atomic_fetch_sub,
> we would need to include stdatomic.h in dim_vector.h.  I didn't think
> that was a good idea as it could conflict with other C++ header files.
>
> When I tried to include stdatomic.h in oct-refcount.h and use those
> functions to provide direct replacements for the old OCTAVE_ATOMIC_*
> macros, I ran into errors.  Testing now, I get errors when using g++ to
> compile a simple C++ file that has only
>
>   #include <stdatomic.h>
>
> in it.  So it seems best to me to just use it from C and provide wrappers
> that can be used in C++.
>

Maybe my misinterpretation, but I thought to include the C++ header file
<atomic>, rather than the C header file <stdatomic.h>.  I was looking at
this reference: http://www.cplusplus.com/reference/atomic/ which seems to
show that atomic_fetch_add exists under C++, but that the prototype we need
to use may require casting to volatile.

However, I couldn't get it to compile after making those changes, so it is
harder than I think.

--Rik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]