From 02e8e9c3ea130882c50326ed83240e29eeffb854 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 25 Nov 2011 17:26:11 +0100 Subject: [PATCH] fixed bug that kept tls emulation from working --- compiler/semfold.nim | 6 +++--- lib/system/threads.nim | 9 +++++---- tests/specials.nim | 2 +- tests/threads/threadex.nim | 31 +++++++++++++++---------------- todo.txt | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/compiler/semfold.nim b/compiler/semfold.nim index afa1090a75..f1c92cdc37 100755 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -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) diff --git a/lib/system/threads.nim b/lib/system/threads.nim index c6b6b4d7c1..ce07f0c3bf 100755 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -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.} = diff --git a/tests/specials.nim b/tests/specials.nim index a8473e34f9..247f5d770b 100644 --- a/tests/specials.nim +++ b/tests/specials.nim @@ -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" diff --git a/tests/threads/threadex.nim b/tests/threads/threadex.nim index 5b80554132..967789ba61 100755 --- a/tests/threads/threadex.nim +++ b/tests/threads/threadex.nim @@ -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 diff --git a/todo.txt b/todo.txt index 2beee17a43..10f525ed0b 100755 --- a/todo.txt +++ b/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