- std::atomic<std::shared_ptr<T>>... - 4 Updates
- differential reference counting... - 2 Updates
- Win32: WaitOnAddress vs. WaitForSingleObject - 1 Update
- merge-sort with alloca()-buffer - 1 Update
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 27 11:40PM -0800 I am wondering if anybody can run the following C++20 program and report its output. It is checking to see if an atomic shared_ptr is actually lockfree. On my compiler MSVC 2019, I am getting a 0, or false. So, this means its not lock-free! Its a damn shame. Afaict, there is no reason why std::atomic<std::shared_ptr<T>> should not be 100% lock-free. https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic2 ____________________________ #include <iostream> #include <memory> #include <atomic> int main() { std::atomic<std::shared_ptr<long>> instance; std::cout << "instance.is_lock_free = " << instance.is_lock_free() << "\n"; return 0; } ____________________________ The reason I ask is because if your compiler returns a true, well, this means that we can implement lock-free proxy collectors directly in the C++20 standard using atomic shared_ptrs, without having to manually create the reference counting logic. Think of a proxy collector as a sort of "poor mans" read copy update. https://en.wikipedia.org/wiki/Read-copy-update |
Ian Collins <ian-news@hotmail.com>: Jan 28 09:41PM +1300 On 28/01/2021 20:40, Chris M. Thomasson wrote: > return 0; > } > ____________________________ No luck with g++/clang++ on Linux (or probably anywhere): $ g++ -std=c++20 /tmp/lf.cc In file included from /tmp/lf.cc:3: /usr/include/c++/10/atomic: In instantiation of 'struct std::atomic<std::shared_ptr<long int> >': /tmp/lf.cc:8:41: required from here /usr/include/c++/10/atomic:195:21: error: static assertion failed: std::atomic requires a trivially copyable type 195 | static_assert(__is_trivially_copyable(_Tp), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Ian. |
Ian Collins <ian-news@hotmail.com>: Jan 28 09:57PM +1300 On 28/01/2021 21:41, Ian Collins wrote: >> } >> ____________________________ > No luck with g++/clang++ on Linux (or probably anywhere): $ g++ --version g++ (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0 $ clang++ --version Ubuntu clang version 12.0.0-++20201226063812+badf0f20f3b3-1~exp1~20201226174505.2125 -- Ian. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 28 11:44AM -0800 On 1/28/2021 12:41 AM, Ian Collins wrote: >> } >> ____________________________ > No luck with g++/clang++ on Linux Yeah. Its a new feature of C++20. So, its going to take some time for the compiler vendors to finally get around to properly implementing, and testing/verifying it. Imvvvvho, they really need to "strive" to make it at least lock-free. Now, there might be a problem with that... Humm... Patents! Several methods to get lock-free, or even wait-free implementations do indeed have patents. So, if they cannot come up with their own algorithms, they might have to license existing techniques... > (or probably anywhere): Well, I can actually get it to compile and run on MSVC 2019 using the /std:c++latest option. This makes the compiler work within the "Preview - Features from the Latest C++ Working Draft" mode. However, its reporting that the impl is not lock-free. That is a rather big problem wrt using it to implement a proxy collector, or poor mans RCU if you will... It is nice that they are actually working on it. To be quite honest, I was rather surprised that it works on MSVC at all. > std::atomic requires a trivially copyable type > 195 | static_assert(__is_trivially_copyable(_Tp), > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ They must not have got around to creating it yet. I bet they are working on it. The feature is nice because it gives std::shared_ptr strong thread safety guarantees. One way to do it was created by Joe Seigh via his really neat atomic_ptr: http://atomic-ptr-plus.sourceforge.net which requires DWCAS. Having a lock-free, or ideally wait-free, std::atomic<std::shared_ptr<T>> would make it really easy to create a proxy collector in pure C++. It would allow for poor mans RCU using the standard and eliminate the need for a user to manually implement the special differential reference counting. Fwiw, I am almost finished porting one of my proxy collectors to C++17. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 27 09:23PM -0800 Dmitry Vyukov, my good friend way back on comp.programming.threads wrote up a pretty good and to the point description on the overall technique: http://www.1024cores.net/home/lock-free-algorithms/object-life-time-management/differential-reference-counting Now, I used to have a nice example program up under my comcast account way back in 2003-2007, however comcast deleted all of their web access. I think I lost it forever. Need to try the way back machine. Dmitry kindly included a link to my old stuff here: http://www.1024cores.net/home/lock-free-algorithms/links (search the text of the page for my last name) The link was to: http://webpages.charter.net/appcore/ However, its deader than dead now. Dmitry knew it was special: https://groups.google.com/g/comp.programming.threads/c/ghfE_KPh_LU/m/Mb6vnbVjFNwJ He references my work, dead links: http://webpages.charter.net/appcore/misc/pc_sample_c.html Now, I need to either find it on the way back machine, or recreate it from scratch. Iirc, it used over alignment to store a little reference count in the proxy collector anchor. I am going to reimplement my differential reference counting thing in this thread using C++17. Dmitry mentions my name again here: http://www.1024cores.net/home/lock-free-algorithms/object-life-time-management/differential-reference-counting/implementation this is going to make my mind explode. This was so long ago! However, I think I can create it from scratch using pure C++17 without going to the way back machine... However... I thank Bonita for making me want to do this. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 27 09:56PM -0800 On 1/27/2021 9:23 PM, Chris M. Thomasson wrote: > kindly included a link to my old stuff here: > http://www.1024cores.net/home/lock-free-algorithms/links > (search the text of the page for my last name) [...] > think I can create it from scratch using pure C++17 without going to the > way back machine... > However... I thank Bonita for making me want to do this. Humm... a First start would be to port the following proxy collector I created to pure C++17. Here is a full implementation, but it uses Relacy Race Detector: https://groups.google.com/g/lock-free/c/X3fuuXknQF0/m/0VF_u-7shrsJ code: https://pastebin.com/raw/f71480694 This should be rather easy to port. However, I need to run it again in Relacy, just for good ol' times... ;^) |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 27 09:04PM -0800 On 1/26/2021 9:09 PM, Chris M. Thomasson wrote: > seem. > I basically proved how it violates Joes patent when he worked over at > IBM. Its radically similar in multiple key areas. I think I finally found it: https://groups.google.com/g/comp.programming.threads/c/8slBGARhQug/m/CclWCyh69NkJ The Sun patent totally infringes on prior art. It should have never been issued. |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jan 27 07:45PM -0800 On 1/26/2021 6:22 PM, Ian Collins wrote: >> to work fine, then crash at a random time. Serious error. > When you attempt a discussion with someone who can't even quote > correctly, what else do you expect? I was trying to see if she could somehow, sort of, "change". Basically, its been a horrible failure. Damn. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment