diff options
author | Hiroki Noda <kubo39@gmail.com> | 2020-01-30 01:33:21 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-29 17:33:21 +0100 |
commit | 3ab127423199fa71462be7263b1820f974c3d7c2 (patch) | |
tree | 57f86c0533f2a8979a2be030a3a35cd3502da7c0 /lib | |
parent | 2ecef8f779b6e5639145a5b2d2aaac6d9775c9eb (diff) | |
download | Nim-3ab127423199fa71462be7263b1820f974c3d7c2.tar.gz |
Thread attributes should be destroyed using the pthread_attr_destroy() (#13293)
On some OSes (such as FreeBSD or Solaris), pthread_attr_init allocate memory. So it is necessary to deallocate that memory by using pthread_attr_destroy.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/threadlocalstorage.nim | 6 | ||||
-rw-r--r-- | lib/system/threads.nim | 5 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/system/threadlocalstorage.nim b/lib/system/threadlocalstorage.nim index aea56e4e7..117af4c25 100644 --- a/lib/system/threadlocalstorage.nim +++ b/lib/system/threadlocalstorage.nim @@ -151,9 +151,11 @@ else: tv_sec: Time tv_nsec: clong - proc pthread_attr_init(a1: var Pthread_attr) {. + proc pthread_attr_init(a1: var Pthread_attr): cint {. importc, header: pthreadh.} - proc pthread_attr_setstacksize(a1: var Pthread_attr, a2: int) {. + proc pthread_attr_setstacksize(a1: var Pthread_attr, a2: int): cint {. + importc, header: pthreadh.} + proc pthread_attr_destroy(a1: var Pthread_attr): cint {. importc, header: pthreadh.} proc pthread_create(a1: var SysThread, a2: var Pthread_attr, diff --git a/lib/system/threads.nim b/lib/system/threads.nim index 1f955307b..54b07e467 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -313,10 +313,11 @@ else: t.dataFn = tp when hasSharedHeap: t.core.stackSize = ThreadStackSize var a {.noinit.}: Pthread_attr - pthread_attr_init(a) - pthread_attr_setstacksize(a, ThreadStackSize) + doAssert pthread_attr_init(a) == 0 + doAssert pthread_attr_setstacksize(a, ThreadStackSize) == 0 if pthread_create(t.sys, a, threadProcWrapper[TArg], addr(t)) != 0: raise newException(ResourceExhaustedError, "cannot create thread") + doAssert pthread_attr_destroy(a) == 0 proc pinToCpu*[Arg](t: var Thread[Arg]; cpu: Natural) = ## Pins a thread to a `CPU`:idx:. |