OSDN Git Service

Fix potential race condition on CTS TC pthread_gettid_np
authorJunjie Hu <junjie.hu@mediatek.com>
Wed, 11 Nov 2015 04:52:25 +0000 (12:52 +0800)
committerJunjie Hu <junjie.hu@mediatek.com>
Wed, 11 Nov 2015 04:54:52 +0000 (04:54 +0000)
commit4f8010293506d4e08d184e66bf4af44ef3483611
treed1c073a2a0207b48af767f78592155ffe9768692
parent93a91f0cf4f015762ac1ed57395c4c0de8ba7db3
Fix potential race condition on CTS TC pthread_gettid_np

Root cause:
If start_routine thread exits before pthread_gettid_np is invokded, the "tid" field
will be cleared so that pthread_gettid_np will get "0" (which is cleared by kernel,
due to the flag "CLONE_CHILD_CLEARTID" is set while calling clone system call inside
pthread_create).

Proposed patch:
Use a mutex to guarantee pthread_gettid_np will be invoked and returned before the
start_routine exits

Signed-off-by: Junjie Hu <junjie.hu@mediatek.com>
Change-Id: I22411f1b0f7446d76a0373cef4ccec858fac7018
tests/pthread_test.cpp [changed mode: 0644->0755]