Bug 16564 – KRRegion.empty sometimes returns Ternary.no

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-29T09:20:58Z
Last change time
2017-12-18T22:56:58Z
Assigned to
alex.jercaianu
Creator
Temtaime

Comments

Comment #0 by temtaime — 2016-09-29T09:20:58Z
I just tried it as video memory allocator for my engine and empty sometimes don't work: try to allocate and then deallocate in a random order. For example void main() { ubyte[256 * 1024] buf; auto a = KRRegion!()(buf); while(true) { void[][] bufs; foreach(_; 0..10_000) { bufs ~= a.allocate(uniform(1, buf.length)); } foreach(b; bufs.randomCover) { a.deallocate(b); } if(a.empty == Ternary.no) break; } writeln(`all the elements are freed but allocator is not empty !`); }
Comment #1 by github-bugzilla — 2017-01-19T13:50:31Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8a69b104513d5f95e31be65b04a6502f559a95c0 fix issue 16564 https://github.com/dlang/phobos/commit/bb27aa7bd2b6863d50c3f19016ad8f4476709748 Merge pull request #5029 from somzzz/issue_16564 fix issue 16564 - KRRegion.empty sometimes returns Ternary.no
Comment #2 by github-bugzilla — 2017-01-24T11:55:02Z
Comment #3 by github-bugzilla — 2017-03-22T12:21:44Z
Comment #4 by temtaime — 2017-07-05T14:39:16Z
Increasing buffer size from 256 kb to 1 mb causes a crash or returns not empty again import std.stdio, std.random, std.typecons, std.algorithm, std.experimental.allocator.building_blocks; void main() { ubyte[1024 * 1024] buf; auto a = KRRegion!()(buf); while(true) { void[][] bufs; foreach(_; 0..10_000) { bufs ~= a.allocate(uniform(1, buf.length)); } foreach(b; bufs.randomCover) { a.deallocate(b); } if(a.empty == Ternary.no) break; } writeln(`all the elements are freed but allocator is not empty !`); }
Comment #5 by dlang-bugzilla — 2017-07-06T21:40:23Z
(In reply to Temtaime from comment #4) > ubyte[1024 * 1024] buf; Are you sure that's not just because you have a 1MB static array on the stack? This program, by itself, crashes on Windows (because of stack overflow): void main() { ubyte[1024 * 1024] buf; }
Comment #6 by andrei — 2017-07-07T21:49:58Z
@Temtaime should this stay open?
Comment #7 by temtaime — 2017-07-13T15:17:57Z
Oh, sorry, my mistake import std.stdio, std.range, std.random, std.typecons, std.algorithm, std.experimental.allocator.building_blocks, core.memory; void main() { ubyte[128 * 1024] b; auto alloc = KRRegion!()(b); //alloc.switchToFreeList; auto k = alloc.allocate(128); assert(alloc.deallocate(k)); assert(alloc.empty == Ternary.yes); } I don't know why but this simplest example asserts. More complex tests are passed. Also it passes if the switch in uncommented
Comment #8 by github-bugzilla — 2017-11-19T02:40:56Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/02074889d5984093b677a1c081c33fbf877360ec Fix Issue 16564 - KRRegion.empty sometimes returns Ternary.no https://github.com/dlang/phobos/commit/1649edd483519a5d60c7b38865e984b46d703cdf Merge pull request #5862 from jercaianu/krr Fix Issue 16564 - KRRegion.empty sometimes returns Ternary.no merged-on-behalf-of: Andrei Alexandrescu <[email protected]>
Comment #9 by github-bugzilla — 2017-12-18T22:56:58Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/02074889d5984093b677a1c081c33fbf877360ec Fix Issue 16564 - KRRegion.empty sometimes returns Ternary.no https://github.com/dlang/phobos/commit/1649edd483519a5d60c7b38865e984b46d703cdf Merge pull request #5862 from jercaianu/krr