-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crash on reserve(1) #26
Comments
Minimum size for reserve is same as minimum size for groups in colony (3), so this is intentional. Will update the documentation. |
Yeah but that'll break when the size being reserved comes from an outside source — like, a data file being read having only 1 or 2 elements. That's a surprising crash for any developer using the library. I'd propose doing it like STL does, silently increasing the size. You already do so for shrink_to_fit(): for 4-byte elements on a 64-bit arch, after a single insert() then shrink_to_fit() the capacity is 72. |
It already does so. |
I'm going to remove the asserts so reserve will silently accept bad input, but I |
I found this as a part of a bigger program — and indeed I can't reproduce the crash (as opposed to assert failure) with a minimal test case either. Can't really do debugging right now — got 4 hours of sleep before a flight. |
All good, if you find the source of the crash do let me know. |
Debugged this on the plane, turns out the crash was actually my fault: plf::colony is not supposed to be thread-safe so that's ok. Bizarrely, the only reserve() call in the program was for thread pool, so running with As for the assert: it's you who gets to declare what's legal with plf::colony's API, but as 1. STL allows too small reserves (which gcc's implementation silently enlarges, like you do with shrink_to_fit()), and 2. it's surprising to the user -- I'd urge you to handle such small reserves some way or another (be it by silently enlarging, or dropping the assert). |
As I've said, I intend to drop the asserts and so rely on the user to investigate the documentation properly when memory sizes don't match their expectations, but neither solution makes me happy. Good to hear the crash isn't my fault :) I would love it if someone made a thread-safe version, I don't have enough experience. |
Could you please make reserve() accept plausible values like 1 (doing something useful, not necessarily exact allocation)? No idea about thread-safe but some folks at work are taking your ideas and plan/toy with plf::colony on persistent memory. This requires some strong discipline about flushing memory writes, doing allocations in atomic or transational way, handling unexpected power loss at any moment without data loss or corruption. This is how I learned about your library -- for now, I'm using it for a personal non-work-related project. |
As I've said, I intend to drop the asserts and silently accept lower-than-possible values. It already rounds up to the minimum group size. |
Changes committed |
ps. Let me know if your work-folk have any success in persistent memory - would be interesting to hear - |
If preallocation via reserve() requests only 1 or 2 elements, there's either a crash — or, in debug builds, an assert failure.
The text was updated successfully, but these errors were encountered: