This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Arfrever, Joshua.J.Cogliati, Vitor.de.Lima, gustavotemple, jrincayc, lbianc, python-dev, vstinner
Date 2015-03-17.11:17:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426591021.34.0.467516202745.issue23644@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-03-17 11:17:01vstinnersetrecipients: + vstinner, Arfrever, jrincayc, python-dev, Joshua.J.Cogliati, Vitor.de.Lima, gustavotemple, lbianc
2015-03-17 11:17:01vstinnersetmessageid: <1426591021.34.0.467516202745.issue23644@psf.upfronthosting.co.za>
2015-03-17 11:17:01vstinnerlinkissue23644 messages
2015-03-17 11:17:01vstinnercreate