STINNER Victor added the comment:

Hum, I'm lost with the problem with C++ :-( What is your use case? Do you want 
to compile CPython with C++? Or compile a third-party extension with C++ and 
this extension includes "Python.h" which includes "pyatomic.h".

For third-party code, pyatomic.h is only needed by PyThreadState_GET() in 
pystate.h. Maybe we should hide completly pyatomic.h. Currently, pyatomic.h is 
not really used if Py_LIMITED_API is defined.

By the way, can you try to compile the extension with Py_LIMITED_API? It should 
just work.


C++ 11 atomic:
---
#include <atomic>

int main()
{
    std::atomic_uintptr_t current;
    current.store(0, std::memory_order_relaxed);
    return 0;
}
---


C++ 11 atomic used with C functions:
---
#include <atomic>

int main()
{
    std::atomic<uintptr_t> current(0);
    std::atomic_store_explicit(&current, (uintptr_t)0, 
std::memory_order_relaxed);
    return 0;
}
---

I didn't find how to use std::atomic_store_explicit with std::atomic_uintptr_t, 
so I used std::atomic<uintptr_t> instead.

"std::atomic_store_explicit(&current, 0, std::memory_order_relaxed);" doesn't 
work: 0 must be explicitly cast to uintptr_t :-(

I tried to hack pyatomic.h to use std::atomic template: see attached 
pyatomic_cpp.patch.

But I don't understand: when PyThreadState_GET() is compiled in C++, should it 
use exactly the same functions of CPython (compiled with C)? It should be 
strange to to use a std::atomic C++ template to access an atomic C variable.

----------
Added file: http://bugs.python.org/file38518/pyatomic_cpp.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23644>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to