more examples

This commit is contained in:
Jaremy Creechley 2024-02-21 22:56:17 -07:00
parent 7dd7894122
commit fde10adac5
3 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,2 @@
--threads:on
--mm:refc

View File

@ -4,6 +4,14 @@ import chronos/threadsync
import chronos/unittest2/asynctests
import taskpools
## This example mocks up a sequence and uses
## a finalizer and GC_fullCollect to more
## deterministically create a memory error.
##
## see `exFailureSeq.nim` for a probablisitc based
## example using a real seq object.
##
type
Seq*[T] = object
data*: ptr UncheckedArray[T]

View File

@ -5,12 +5,22 @@ import chronos/threadsync
import chronos/unittest2/asynctests
import taskpools
## create a probablistically likely failure of
## using sequence memory from another thread
## with refc.
##
## However, unlike `exFailure.nim`, this can take
## a while to run.
##
## It may not always produce an error either, but
## generally does so in a few seconds of running.
##
type
Seq*[T] = object
data*: ptr UncheckedArray[T]
size*: int
template toOpenArray*[T](arr: Seq[T]): auto =
system.toOpenArray(arr.data, 0, arr.size)
@ -20,7 +30,7 @@ proc toArrayHolder*[T](data: seq[T]): Seq[T] =
)
proc worker(data: Seq[char], sig: ThreadSignalPtr) =
os.sleep(100)
os.sleep(300)
echo "running worker: "
echo "worker: ", data.toOpenArray()
for i, c in data.toOpenArray():