From f8d6d74368ea14403d1d455db30b669750e71651 Mon Sep 17 00:00:00 2001 From: Philip Wernersbach Date: Sun, 15 Mar 2015 17:33:46 -0400 Subject: [PATCH 1/2] Fix pthread_create binding when compiling in C++ mode. C++ has different rules for void pointers, which causes the binding to be invalid when compiling in C++ mode. --- lib/system/threads.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/system/threads.nim b/lib/system/threads.nim index 81d9e5d73..d8e011ecb 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -127,7 +127,7 @@ else: importc, header: "".} proc pthread_create(a1: var TSysThread, a2: var TPthread_attr, - a3: proc (x: pointer) {.noconv.}, + a3: proc (x: pointer): pointer {.noconv.}, a4: pointer): cint {.importc: "pthread_create", header: "".} proc pthread_join(a1: TSysThread, a2: ptr pointer): cint {. @@ -315,7 +315,7 @@ when defined(windows): threadProcWrapperBody(closure) # implicitly return 0 else: - proc threadProcWrapper[TArg](closure: pointer) {.noconv.} = + proc threadProcWrapper[TArg](closure: pointer): pointer {.noconv.} = threadProcWrapperBody(closure) {.pop.} From dcf4cee37c6e6fd79658b6a3eb7c130b1d880aee Mon Sep 17 00:00:00 2001 From: Philip Wernersbach Date: Sun, 15 Mar 2015 17:54:57 -0400 Subject: [PATCH 2/2] Add test for fix in f8d6d74368ea14403d1d455db30b669750e71651. --- tests/cpp/tthread_createthread.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/cpp/tthread_createthread.nim diff --git a/tests/cpp/tthread_createthread.nim b/tests/cpp/tthread_createthread.nim new file mode 100644 index 000000000..0dc081268 --- /dev/null +++ b/tests/cpp/tthread_createthread.nim @@ -0,0 +1,14 @@ +discard """ + cmd: "nim cpp --hints:on --threads:on $options $file" +""" + +proc threadMain(a: int) {.thread.} = + discard + +proc main() = + var thread: TThread[int] + + thread.createThread(threadMain, 0) + thread.joinThreads() + +main() \ No newline at end of file