Message238278
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(¤t, (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(¤t, 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. |
|
Date |
User |
Action |
Args |
2015-03-17 11:17:01 | vstinner | set | recipients:
+ vstinner, Arfrever, jrincayc, python-dev, Joshua.J.Cogliati, Vitor.de.Lima, gustavotemple, lbianc |
2015-03-17 11:17:01 | vstinner | set | messageid: <1426591021.34.0.467516202745.issue23644@psf.upfronthosting.co.za> |
2015-03-17 11:17:01 | vstinner | link | issue23644 messages |
2015-03-17 11:17:01 | vstinner | create | |
|