mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 04:57:49 +00:00
fixed bug that kept tls emulation from working
This commit is contained in:
@@ -413,10 +413,10 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||
LocalError(a.info, errCannotEvalXBecauseIncompletelyDefined,
|
||||
"sizeof")
|
||||
result = nil
|
||||
elif a.typ.kind in {tyArray, tyObject, tyTuple}:
|
||||
result = nil
|
||||
elif skipTypes(a.typ, abstractInst).kind in {tyArray,tyObject,tyTuple}:
|
||||
result = nil
|
||||
# XXX: size computation for complex types is still wrong
|
||||
else:
|
||||
else:
|
||||
result = newIntNodeT(getSize(a.typ), n)
|
||||
of mLow:
|
||||
result = newIntNodeT(firstOrd(n.sons[1].typ), n)
|
||||
|
||||
@@ -349,7 +349,7 @@ proc createThread*[TArg](t: var TThread[TArg],
|
||||
if t.sys <= 0:
|
||||
raise newException(EResourceExhausted, "cannot create thread")
|
||||
else:
|
||||
var a: Tpthread_attr
|
||||
var a {.noinit.}: Tpthread_attr
|
||||
pthread_attr_init(a)
|
||||
pthread_attr_setstacksize(a, ThreadStackSize)
|
||||
if pthread_create(t.sys, a, threadProcWrapper[TArg], addr(t)) != 0:
|
||||
@@ -363,9 +363,10 @@ proc myThreadId*[TArg](): TThreadId[TArg] =
|
||||
## returns the thread ID of the thread that calls this proc.
|
||||
result = cast[TThreadId[TArg]](ThreadVarGetValue(globalsSlot))
|
||||
|
||||
proc mainThreadId*[TArg](): TThreadId[TArg] =
|
||||
## returns the thread ID of the main thread.
|
||||
result = cast[TThreadId[TArg]](addr(mainThread))
|
||||
when false:
|
||||
proc mainThreadId*[TArg](): TThreadId[TArg] =
|
||||
## returns the thread ID of the main thread.
|
||||
result = cast[TThreadId[TArg]](addr(mainThread))
|
||||
|
||||
when useStackMaskHack:
|
||||
proc runMain(tp: proc () {.thread.}) {.compilerproc.} =
|
||||
|
||||
@@ -117,7 +117,7 @@ proc runThreadTests(r: var TResults, options: string) =
|
||||
runSingleTest(r, "tests/threads" / filename, options & " -tlsEmulation:on")
|
||||
|
||||
test "tactors"
|
||||
#test "threadex"
|
||||
test "threadex"
|
||||
#test "threadring"
|
||||
#test "tthreadanalysis"
|
||||
#test "tthreadsort"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
output: ""
|
||||
outputsub: "All rights reserved."
|
||||
"""
|
||||
|
||||
type
|
||||
@@ -7,39 +7,38 @@ type
|
||||
mLine, mEof
|
||||
TMsg = object {.pure, final.}
|
||||
case k: TMsgKind
|
||||
of mEof: backTo: TThreadId[int]
|
||||
of mEof: nil
|
||||
of mLine: data: string
|
||||
|
||||
var
|
||||
consumer: TThread[TMsg]
|
||||
producer, consumer: TThread[void]
|
||||
chan: TChannel[TMsg]
|
||||
printedLines = 0
|
||||
|
||||
proc consume() {.thread.} =
|
||||
while true:
|
||||
var x = recv[TMsg]()
|
||||
if x.k == mEof:
|
||||
x.backTo.send(printedLines)
|
||||
break
|
||||
var x = recv(chan)
|
||||
if x.k == mEof: break
|
||||
echo x.data
|
||||
atomicInc(printedLines)
|
||||
|
||||
proc produce() =
|
||||
proc produce() {.thread.} =
|
||||
var m: TMsg
|
||||
var input = open("readme.txt")
|
||||
while not endOfFile(input):
|
||||
if consumer.ready:
|
||||
if chan.ready:
|
||||
m.data = input.readLine()
|
||||
consumer.send(m)
|
||||
chan.send(m)
|
||||
close(input)
|
||||
m.k = mEof
|
||||
m.backTo = mainThreadId[int]()
|
||||
consumer.send(m)
|
||||
var result = recv[int]()
|
||||
echo result
|
||||
chan.send(m)
|
||||
|
||||
createThread(consumer, consume)
|
||||
produce()
|
||||
open(chan)
|
||||
createThread[void](consumer, consume)
|
||||
createThread[void](producer, produce)
|
||||
joinThread(consumer)
|
||||
joinThread(producer)
|
||||
|
||||
close(chan)
|
||||
echo printedLines
|
||||
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -1,7 +1,6 @@
|
||||
version 0.8.14
|
||||
==============
|
||||
|
||||
- fix thread tests
|
||||
- deprecate endOfFile and readline
|
||||
|
||||
version 0.9.0
|
||||
@@ -32,6 +31,7 @@ version 0.9.0
|
||||
- change how comments are part of the AST
|
||||
- optional indentation for 'case' statement; hm, keep in mind other syntax
|
||||
changes that people want; may turn out to be a bad idea
|
||||
- activate more thread tests
|
||||
|
||||
|
||||
Bugs
|
||||
|
||||
Reference in New Issue
Block a user