mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
* defaults to Orc * bootstrap using refc * use gc * init orc defines * unregister orc * fix gc * fix commands * add prepareMutation for orc * enable deepcopy for orc * prepareMutation * more fixes * some cases * bug #20081 * partial fixes * partial fixes * fixes command line * more fixes * build Nim with refc * use gc * more fixes * rstore * orc doesn't support threadpool * more shallowCopy * more fixes * fixes unsafeNew * workarounds * small * more fixes * fixes some megatest * tcodegenbugs1 refc * fxies megatest * build nimble with refc * workaround tensordsl tests * replace shallowCopy with move * fixes action * workaround * add todo * fixes important packages * unpublic unregisterArcOrc * fixes cpp * enable windows Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
73 lines
1.6 KiB
Nim
73 lines
1.6 KiB
Nim
discard """
|
|
output: '''ob2 @[]
|
|
ob @[]
|
|
ob3 @[]
|
|
3
|
|
ob2 @[]
|
|
ob @[]
|
|
ob3 @[]
|
|
'''
|
|
matrix: "--mm:refc"
|
|
"""
|
|
|
|
# bug #4776
|
|
|
|
import tables
|
|
|
|
type
|
|
Base* = ref object of RootObj
|
|
someSeq: seq[int]
|
|
baseData: array[40000, byte]
|
|
Derived* = ref object of Base
|
|
data: array[40000, byte]
|
|
|
|
type
|
|
ThreadPool = ref object
|
|
threads: seq[ptr Thread[ThreadArg]]
|
|
channels: seq[ThreadArg]
|
|
TableChannel = Channel[TableRef[string, Base]]
|
|
ThreadArg = ptr TableChannel
|
|
|
|
var globalTable {.threadvar.}: TableRef[string, Base]
|
|
globalTable = newTable[string, Base]()
|
|
let d = new(Derived)
|
|
globalTable.add("ob", d)
|
|
globalTable.add("ob2", d)
|
|
globalTable.add("ob3", d)
|
|
|
|
proc testThread(channel: ptr TableChannel) {.thread.} =
|
|
globalTable = channel[].recv()
|
|
for k, v in pairs globaltable:
|
|
echo k, " ", v.someSeq
|
|
var myObj: Base
|
|
deepCopy(myObj, globalTable["ob"])
|
|
myObj.someSeq = newSeq[int](100)
|
|
let table = channel[].recv() # same table
|
|
echo table.len
|
|
for k, v in mpairs table:
|
|
echo k, " ", v.someSeq
|
|
assert(table.contains("ob")) # fails!
|
|
assert(table.contains("ob2")) # fails!
|
|
assert(table.contains("ob3")) # fails!
|
|
|
|
var channel: TableChannel
|
|
|
|
proc newThreadPool(threadCount: int) = #: ThreadPool =
|
|
#new(result)
|
|
#result.threads = newSeq[ptr Thread[ThreadArg]](threadCount)
|
|
#var channel = cast[ptr TableChannel](allocShared0(sizeof(TableChannel)))
|
|
channel.open()
|
|
channel.send(globalTable)
|
|
channel.send(globalTable)
|
|
#createThread(threadPtr[], testThread, addr channel)
|
|
testThread(addr channel)
|
|
#result.threads[i] = threadPtr
|
|
|
|
proc stop(p: ThreadPool) =
|
|
for t in p.threads:
|
|
joinThread(t[])
|
|
dealloc(t)
|
|
|
|
|
|
newThreadPool(1)#.stop()
|