summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-01-30 21:11:37 +0100
committerAraq <rumpf_a@web.de>2017-01-30 21:11:37 +0100
commit79f4b37d3b251ede2704d278a0914daa42d361c9 (patch)
tree90c0c73dece25a28236f12975fdefaa3cbc13428
parentb26e6e3589f0564c6c3838cdd09d810dea6b1080 (diff)
downloadNim-79f4b37d3b251ede2704d278a0914daa42d361c9.tar.gz
added test case; threadex example crashes now
-rw-r--r--lib/system/alloc.nim6
-rw-r--r--lib/system/gc.nim2
-rw-r--r--tests/testament/categories.nim1
-rw-r--r--tests/threads/tracy_allocator.nim25
4 files changed, 32 insertions, 2 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index e630aa3c1..37fd07719 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -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:
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index 18d41219d..686729a68 100644
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -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
diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim
index a7e0909c2..e629410e7 100644
--- a/tests/testament/categories.nim
+++ b/tests/testament/categories.nim
@@ -201,6 +201,7 @@ proc threadTests(r: var TResults, cat: Category, options: string) =
   #test "tthreadanalysis3"
   test "tthreadheapviolation1"
   test "tonthreadcreation"
+  test "tracy_allocator"
 
 # ------------------------- IO tests ------------------------------------------
 
diff --git a/tests/threads/tracy_allocator.nim b/tests/threads/tracy_allocator.nim
new file mode 100644
index 000000000..e8f0ec927
--- /dev/null
+++ b/tests/threads/tracy_allocator.nim
@@ -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"