fixed bug that kept tls emulation from working

This commit is contained in:
Araq 2011-11-25 17:26:11 +01:00
commit 02e8e9c3ea
5 changed files with 25 additions and 25 deletions

View file

@ -413,10 +413,10 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
LocalError(a.info, errCannotEvalXBecauseIncompletelyDefined, LocalError(a.info, errCannotEvalXBecauseIncompletelyDefined,
"sizeof") "sizeof")
result = nil result = nil
elif a.typ.kind in {tyArray, tyObject, tyTuple}: elif skipTypes(a.typ, abstractInst).kind in {tyArray,tyObject,tyTuple}:
result = nil result = nil
# XXX: size computation for complex types is still wrong # XXX: size computation for complex types is still wrong
else: else:
result = newIntNodeT(getSize(a.typ), n) result = newIntNodeT(getSize(a.typ), n)
of mLow: of mLow:
result = newIntNodeT(firstOrd(n.sons[1].typ), n) result = newIntNodeT(firstOrd(n.sons[1].typ), n)

View file

@ -349,7 +349,7 @@ proc createThread*[TArg](t: var TThread[TArg],
if t.sys <= 0: if t.sys <= 0:
raise newException(EResourceExhausted, "cannot create thread") raise newException(EResourceExhausted, "cannot create thread")
else: else:
var a: Tpthread_attr var a {.noinit.}: Tpthread_attr
pthread_attr_init(a) pthread_attr_init(a)
pthread_attr_setstacksize(a, ThreadStackSize) pthread_attr_setstacksize(a, ThreadStackSize)
if pthread_create(t.sys, a, threadProcWrapper[TArg], addr(t)) != 0: 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. ## returns the thread ID of the thread that calls this proc.
result = cast[TThreadId[TArg]](ThreadVarGetValue(globalsSlot)) result = cast[TThreadId[TArg]](ThreadVarGetValue(globalsSlot))
proc mainThreadId*[TArg](): TThreadId[TArg] = when false:
## returns the thread ID of the main thread. proc mainThreadId*[TArg](): TThreadId[TArg] =
result = cast[TThreadId[TArg]](addr(mainThread)) ## returns the thread ID of the main thread.
result = cast[TThreadId[TArg]](addr(mainThread))
when useStackMaskHack: when useStackMaskHack:
proc runMain(tp: proc () {.thread.}) {.compilerproc.} = proc runMain(tp: proc () {.thread.}) {.compilerproc.} =

View file

@ -117,7 +117,7 @@ proc runThreadTests(r: var TResults, options: string) =
runSingleTest(r, "tests/threads" / filename, options & " -tlsEmulation:on") runSingleTest(r, "tests/threads" / filename, options & " -tlsEmulation:on")
test "tactors" test "tactors"
#test "threadex" test "threadex"
#test "threadring" #test "threadring"
#test "tthreadanalysis" #test "tthreadanalysis"
#test "tthreadsort" #test "tthreadsort"

View file

@ -1,5 +1,5 @@
discard """ discard """
output: "" outputsub: "All rights reserved."
""" """
type type
@ -7,39 +7,38 @@ type
mLine, mEof mLine, mEof
TMsg = object {.pure, final.} TMsg = object {.pure, final.}
case k: TMsgKind case k: TMsgKind
of mEof: backTo: TThreadId[int] of mEof: nil
of mLine: data: string of mLine: data: string
var var
consumer: TThread[TMsg] producer, consumer: TThread[void]
chan: TChannel[TMsg]
printedLines = 0 printedLines = 0
proc consume() {.thread.} = proc consume() {.thread.} =
while true: while true:
var x = recv[TMsg]() var x = recv(chan)
if x.k == mEof: if x.k == mEof: break
x.backTo.send(printedLines)
break
echo x.data echo x.data
atomicInc(printedLines) atomicInc(printedLines)
proc produce() = proc produce() {.thread.} =
var m: TMsg var m: TMsg
var input = open("readme.txt") var input = open("readme.txt")
while not endOfFile(input): while not endOfFile(input):
if consumer.ready: if chan.ready:
m.data = input.readLine() m.data = input.readLine()
consumer.send(m) chan.send(m)
close(input) close(input)
m.k = mEof m.k = mEof
m.backTo = mainThreadId[int]() chan.send(m)
consumer.send(m)
var result = recv[int]()
echo result
createThread(consumer, consume) open(chan)
produce() createThread[void](consumer, consume)
createThread[void](producer, produce)
joinThread(consumer) joinThread(consumer)
joinThread(producer)
close(chan)
echo printedLines echo printedLines

View file

@ -1,7 +1,6 @@
version 0.8.14 version 0.8.14
============== ==============
- fix thread tests
- deprecate endOfFile and readline - deprecate endOfFile and readline
version 0.9.0 version 0.9.0
@ -32,6 +31,7 @@ version 0.9.0
- change how comments are part of the AST - change how comments are part of the AST
- optional indentation for 'case' statement; hm, keep in mind other syntax - optional indentation for 'case' statement; hm, keep in mind other syntax
changes that people want; may turn out to be a bad idea changes that people want; may turn out to be a bad idea
- activate more thread tests
Bugs Bugs