| Paavo Helde <myfirstname@osa.pri.ee>: Jun 20 10:02PM +0300 20.06.2021 21:09 Paavo Helde kirjutas: > Well, I took your word and measured the overheads. FYI, results from a Linux machine with gcc. The synchronization overhead appears not so large as on Windows, but on the other hand any supposed losses of std::shared_ptr seem to be even smaller, compared to a pure std::atomic<int>: > g++ test1.cpp -std=c++17 -O3 -pthread > ./a.out hardware_concurrency: 16 Async pointer : result =1056964608, total time = 14.7805 s Atomic pointer : result =1056964608, total time = 21.0752 s std::shared_ptr : result =1056964608, total time = 21.427 s std::make_shared: result =1056964608, total time = 21.2404 s |
| "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 20 02:56PM -0700 On 6/20/2021 11:09 AM, Paavo Helde wrote: > (including std::atomic_ptr with std::memory_order_relaxed) means heavy > penalties, whereas extra pointers or extra dynamic allocations involved > with std::shared_ptr only cost peanuts. What is std::atomic_ptr? > The code is below, feel free to try it out on your favorite platform. My > numbers are from MSVC++ 2019, x64 Release build. > ------------------------------------ [...] > private: > std::atomic<int> refcount; > }; [...] You have some issues with your memory order here, relaxed is not going to cut it. Also, better try to isolate the refcount on a cacheline, and pad it. |
| Sam <sam@email-scan.com>: Jun 20 07:03PM -0400 Paavo Helde writes: > std::shared_ptr only cost peanuts. > I guess one should better stop complaining about the shared_ptr design, it > appears to be pretty fine for its intended purpose (safe usage). It's going to be quite a neat trick to implement shared_ptr without keeping an atomic reference count, somewhere. In fact, digging into shared_ptr's innards what does one find, but an _Atomic_word, whose operations use acquire/release memory ordering which, according to the above, should impose a heavy penalty. Something in your observed results does not add up, in this respect. However, the shortcoming with shared_ptr that I see, and I explained – only a small part of it relates to this specific area. |
| 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