added test case; threadex example crashes now

This commit is contained in:
Araq 2017-01-30 21:11:37 +01:00
commit 79f4b37d3b
4 changed files with 32 additions and 2 deletions

View file

@ -103,7 +103,7 @@ type
root, deleted, last, freeAvlNodes: PAvlNode root, deleted, last, freeAvlNodes: PAvlNode
locked, blockChunkSizeIncrease: bool # if locked, we cannot free pages. locked, blockChunkSizeIncrease: bool # if locked, we cannot free pages.
nextChunkSize: int nextChunkSize: int
{.deprecated: [TLLChunk: LLChunk, TAvlNode: AvlNode, TMemRegion: MemRegion].} {.deprecated: [TMemRegion: MemRegion].}
# shared: # shared:
var var
@ -312,6 +312,8 @@ proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
incCurrMem(a, size) incCurrMem(a, size)
inc(a.freeMem, size) inc(a.freeMem, size)
result.heapLink = a.heapLink result.heapLink = a.heapLink
when defined(debugHeapLinks):
cprintf("owner: %p; result: %p; next pointer %p\n", addr(a), result, result.heapLink)
result.origSize = size result.origSize = size
a.heapLink = result a.heapLink = result
@ -713,6 +715,8 @@ proc deallocOsPages(a: var MemRegion) =
# we free every 'ordinarily' allocated page by iterating over the page bits: # we free every 'ordinarily' allocated page by iterating over the page bits:
var it = a.heapLink var it = a.heapLink
while it != nil: while it != nil:
when defined(debugHeapLinks):
cprintf("owner %p; dealloc A: %p\n", addr(a), it)
let next = it.heapLink let next = it.heapLink
sysAssert it.origSize >= PageSize, "origSize too small" sysAssert it.origSize >= PageSize, "origSize too small"
# note: # note:

View file

@ -472,7 +472,7 @@ proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1") gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
collectCT(gch) collectCT(gch)
var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell))) var res = cast[PCell](rawAlloc(gch.region, size + sizeof(Cell)))
gcAssert typ.kind in {tyString, tySequence} or size >= typ.base.size, "size too small" #gcAssert typ.kind in {tyString, tySequence} or size >= typ.base.size, "size too small"
gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2") gcAssert((cast[ByteAddress](res) and (MemAlign-1)) == 0, "newObj: 2")
# now it is buffered in the ZCT # now it is buffered in the ZCT
res.typ = typ res.typ = typ

View file

@ -201,6 +201,7 @@ proc threadTests(r: var TResults, cat: Category, options: string) =
#test "tthreadanalysis3" #test "tthreadanalysis3"
test "tthreadheapviolation1" test "tthreadheapviolation1"
test "tonthreadcreation" test "tonthreadcreation"
test "tracy_allocator"
# ------------------------- IO tests ------------------------------------------ # ------------------------- IO tests ------------------------------------------

View file

@ -0,0 +1,25 @@
discard """
output: '''true'''
"""
var somethingElse {.threadvar.}: ref string
type MyThread = Thread[void]
proc asyncThread() {.thread.} =
new somethingElse
var threads = newSeq[ptr Thread[void]](8)
for c in 1..1_000:
#echo "Test " & $c
for i in 0..<threads.len:
var t = cast[ptr Thread[void]](alloc0(sizeof(MyThread)))
threads[i] = t
createThread(t[], asyncThread)
for t in threads:
joinThread(t[])
dealloc(t)
echo "true"