mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-30 04:07:55 +00:00
added test case; threadex example crashes now
This commit is contained in:
@@ -103,7 +103,7 @@ type
|
||||
root, deleted, last, freeAvlNodes: PAvlNode
|
||||
locked, blockChunkSizeIncrease: bool # if locked, we cannot free pages.
|
||||
nextChunkSize: int
|
||||
{.deprecated: [TLLChunk: LLChunk, TAvlNode: AvlNode, TMemRegion: MemRegion].}
|
||||
{.deprecated: [TMemRegion: MemRegion].}
|
||||
|
||||
# shared:
|
||||
var
|
||||
@@ -312,6 +312,8 @@ proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
|
||||
incCurrMem(a, size)
|
||||
inc(a.freeMem, size)
|
||||
result.heapLink = a.heapLink
|
||||
when defined(debugHeapLinks):
|
||||
cprintf("owner: %p; result: %p; next pointer %p\n", addr(a), result, result.heapLink)
|
||||
result.origSize = size
|
||||
a.heapLink = result
|
||||
|
||||
@@ -713,6 +715,8 @@ proc deallocOsPages(a: var MemRegion) =
|
||||
# we free every 'ordinarily' allocated page by iterating over the page bits:
|
||||
var it = a.heapLink
|
||||
while it != nil:
|
||||
when defined(debugHeapLinks):
|
||||
cprintf("owner %p; dealloc A: %p\n", addr(a), it)
|
||||
let next = it.heapLink
|
||||
sysAssert it.origSize >= PageSize, "origSize too small"
|
||||
# note:
|
||||
|
||||
@@ -472,7 +472,7 @@ proc rawNewObj(typ: PNimType, size: int, gch: var GcHeap): pointer =
|
||||
gcAssert(typ.kind in {tyRef, tyString, tySequence}, "newObj: 1")
|
||||
collectCT(gch)
|
||||
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")
|
||||
# now it is buffered in the ZCT
|
||||
res.typ = typ
|
||||
|
||||
@@ -201,6 +201,7 @@ proc threadTests(r: var TResults, cat: Category, options: string) =
|
||||
#test "tthreadanalysis3"
|
||||
test "tthreadheapviolation1"
|
||||
test "tonthreadcreation"
|
||||
test "tracy_allocator"
|
||||
|
||||
# ------------------------- IO tests ------------------------------------------
|
||||
|
||||
|
||||
25
tests/threads/tracy_allocator.nim
Normal file
25
tests/threads/tracy_allocator.nim
Normal 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"
|
||||
Reference in New Issue
Block a user