mirror of
https://github.com/logos-storage/apatheia.git
synced 2026-01-02 13:03:11 +00:00
more examples
This commit is contained in:
parent
7dd7894122
commit
fde10adac5
2
tests/exampleGcFailures/config.nims
Normal file
2
tests/exampleGcFailures/config.nims
Normal file
@ -0,0 +1,2 @@
|
||||
--threads:on
|
||||
--mm:refc
|
||||
@ -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]
|
||||
|
||||
@ -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():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user