diff --git a/openharmony开源软件阅读报告.docx b/openharmony开源软件阅读报告.docx new file mode 100644 index 0000000..e477096 Binary files /dev/null and b/openharmony开源软件阅读报告.docx differ diff --git a/pthread_atfork_test_001.cpp b/pthread_atfork_test_001.cpp new file mode 100644 index 0000000..0b8f7a6 --- /dev/null +++ b/pthread_atfork_test_001.cpp @@ -0,0 +1,218 @@ +/*1212 + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "it_pthread_test.h" + +static volatile int g_count = 0; +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; +static int g_testAtforkCount = 0; +static int g_testAtforkPrepare = 0; +static int g_testAtforkParent = 0; +static int g_testAtforkChild = 0; +static const int SLEEP_TIME = 2; + +static void Prepare() +{ + int err; + ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount); +// һ꣬ڼǷ㡣㣬ԻֹͣӦϢȷ g_testAtforkCount 1 + err = pthread_mutex_lock(&g_lock); +// дͼȡ g_lockȡɹg_testAtforkPrepare ʾִ߳׼ + ICUNIT_ASSERT_EQUAL_VOID(err, 0, err); + g_testAtforkPrepare++; +} + +static void Parent() +{ + int err; + ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount); + + err = pthread_mutex_unlock(&g_lock); +// дͷ֮ǰ Prepare Ļ g_lock̷߳ٽ + ICUNIT_ASSERT_EQUAL_VOID(err, 0, err); + g_testAtforkParent++; +// g_testAtforkParentʾִز +} + +static void child() +{ + int err; + ICUNIT_ASSERT_EQUAL_VOID(g_testAtforkCount, 1, g_testAtforkCount); + + err = pthread_mutex_unlock(&g_lock); + ICUNIT_ASSERT_EQUAL_VOID(err, 0, err); + g_testAtforkChild++; +// g_testAtforkChildʾӽִز +} + +static void *ThreadProc(void *arg) +{ + int err; + + // һѭֱ g_count ﵽ 5 + while (g_count < 5) { + // ס g_lock g_count ĸ£ֹ޸ġ + err = pthread_mutex_lock(&g_lock); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // g_count ֵʾִһμ + g_count++; + + // SLEEP_AND_YIELD 꺯õǰ߳һʱ䲢ó CPUִ߳С + SLEEP_AND_YIELD(SLEEP_TIME); + + // g_lock̷߳ʱԴ + err = pthread_mutex_unlock(&g_lock); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // ٴε SLEEP_AND_YIELD 꺯õǰ߲߳ó CPU + SLEEP_AND_YIELD(SLEEP_TIME); + } + +EXIT: + return NULL; +} + + +static void *PthreadAtforkTest(void *arg) +{ + int err; + pid_t pid; + pthread_t tid; + int status = 0; + + // ʼ g_count Ͳصı + g_count = 0; + g_testAtforkCount = 0; + g_testAtforkPrepare = 0; + g_testAtforkParent = 0; + g_testAtforkChild = 0; + + // һµ߳ + err = pthread_create(&tid, NULL, ThreadProc, NULL); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // ע fork ǰĴ + err = pthread_atfork(Prepare, Parent, child); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // ²ԼѴ߳ + g_testAtforkCount++; + + // ߲ó CPU + SLEEP_AND_YIELD(SLEEP_TIME); + + // fork() ӽ + pid = fork(); + ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT); // 100000, PID ᳬ 100000 + ICUNIT_GOTO_EQUAL(g_testAtforkPrepare, 1, g_testAtforkPrepare, EXIT); + + // ӽ̵Ĵ߼ + if (pid == 0) { + // ӽУ g_testAtforkChild ǷΪ 1ȷӽ̵״̬ + ICUNIT_GOTO_EQUAL(g_testAtforkChild, 1, g_testAtforkChild, EXIT); + + // ӽ̽ѭֱ g_count ﵽ 5 + while (g_count < 5) { + // g_count + err = pthread_mutex_lock(&g_lock); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // g_count + g_count++; + + // ߲ó CPU + SLEEP_AND_YIELD(SLEEP_TIME); + + // + err = pthread_mutex_unlock(&g_lock); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // ߲ó CPU + SLEEP_AND_YIELD(SLEEP_TIME); + } + + // ӽ˳˳״̬Ϊ 15 + exit(15); // 15, ˳״̬ + } + + // У g_testAtforkParent ǷΪ 1ȷϸ̵״̬ + ICUNIT_GOTO_EQUAL(g_testAtforkParent, 1, g_testAtforkParent, EXIT_WAIT); + + // ȴ߳̽ + err = pthread_join(tid, NULL); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT_WAIT); +// + // ̵ȴӽ˳ + err = waitpid(pid, &status, 0); + status = WEXITSTATUS(status); // ȡӽ̵˳״̬ + ICUNIT_GOTO_EQUAL(err, pid, err, EXIT); + ICUNIT_GOTO_EQUAL(status, 15, status, EXIT); // ӽ̵˳״̬ǷΪ 15 + +EXIT: + return NULL; + +EXIT_WAIT: + // ̵ȴӽ˳ + (void)waitpid(pid, &status, 0); + return NULL; +} + + +static int Testcase() +{ + int ret; + pthread_t newPthread; + int curThreadPri, curThreadPolicy; + pthread_attr_t a = { 0 }; + struct sched_param param = { 0 }; + + ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m); + ICUNIT_ASSERT_EQUAL(ret, 0, -ret); + + curThreadPri = param.sched_priority; + + ret = pthread_attr_init(&a); + pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED); + param.sched_priority = curThreadPri + 2; // 2, adjust the priority. + pthread_attr_setschedparam(&a, ¶m); + ret = pthread_create(&newPthread, &a, PthreadAtforkTest, 0); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newPthread, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return 0; +} + +void ItTestPthreadAtfork001(void) +{ + TEST_ADD_CASE("IT_PTHREAD_ATFORK_001", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION); +} diff --git a/pthread_atfork_test_002.cpp b/pthread_atfork_test_002.cpp new file mode 100644 index 0000000..eb87c81 --- /dev/null +++ b/pthread_atfork_test_002.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "it_pthread_test.h" +#include + +// ϵͳnanosleepúʹǰָ߳ʱ䡣 +extern int nanosleep(const struct timespec *req, struct timespec *rem); + +// ȫֻ g_mux̲ͬ߳ +static pthread_mutex_t g_mux = PTHREAD_MUTEX_INITIALIZER; + +// ȫֱforkصIJ״̬ +static volatile int g_testAtforkCount = 0; // ¼forkļ +static int g_testAtforkPrepare = 0; // ڱʶ׼״̬ļ +static int g_testAtforkParent = 0; // ڱʶ״̬ļ + +// ̺߳Doit½nanosleep +static void *Doit(void *arg) +{ + int err; + struct timespec ts = { 2, 0 }; // ʱΪ2룬ڶΪ루0ʾҪ벿֣ + + // g_testAtforkCountǷΪ1ǣתEXITǩ + ICUNIT_GOTO_EQUAL(g_testAtforkCount, 1, g_testAtforkCount, EXIT); + + // סg_mux֤ԹԴķ̰߳ȫġ + err = pthread_mutex_lock(&g_mux); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // õǰ߳2롣 + (void)nanosleep(&ts, NULL); + + // g_mux + err = pthread_mutex_unlock(&g_mux); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + +EXIT: + // NULLʾûд + return NULL; +} + +// ̺߳Doit1Doitͬǽлµnanosleep +static void *Doit1(void *arg) +{ + int err; + struct timespec ts = { 2, 0 }; // ʱΪ2롣 + + // g_testAtforkCountǷΪ1ǣתEXITǩ + ICUNIT_GOTO_EQUAL(g_testAtforkCount, 1, g_testAtforkCount, EXIT); + + // סg_mux֤ԹԴķ̰߳ȫġ + err = pthread_mutex_lock(&g_mux); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + + // õǰ߳2롣 + (void)nanosleep(&ts, NULL); + + // g_mux + err = pthread_mutex_unlock(&g_mux); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); + +EXIT: + // NULLʾûд + return NULL; +} + +// Prepare׼׶Σͷg_testAtforkPrepare +static void Prepare(void) +{ + int err; + + // Խg_muxûס򷵻ش + err = pthread_mutex_unlock(&g_mux); + ICUNIT_ASSERT_EQUAL_VOID(err, 0, err); // УǷɹɹ + + // g_testAtforkPrepareʾ׼á + g_testAtforkPrepare++; +} + +// Parentڸ̽׶Σȡg_testAtforkParent +static void Parent(void) +{ + int err = pthread_mutex_lock(&g_mux); // סg_mux + ICUNIT_ASSERT_EQUAL_VOID(err, 0, err); // УסǷɹɹ + + // g_testAtforkParentʾѽ׶Ρ + g_testAtforkParent++; +} + +// PthreadAtforkTestǽж߳forkIJԣ֤pthread_atfork()Ϊ +static void *PthreadAtforkTest(void *arg) +{ + int err, ret; + int pid; + int status = 0; + struct timespec ts = { 1, 0 }; // һtimespecṹָnanosleepʱ1롣 + pthread_t tid; // һ߳IDڴ洢̵߳ID + + // ʼȫֱforkصIJ״̬ + g_testAtforkCount = 0; + g_testAtforkPrepare = 0; + g_testAtforkParent = 0; + + // ʹpthread_atforkעᴦֱΪӽ׼Prepare͸̺Parent + // NULLʾûΪӽעᴦ + err = pthread_atfork(Prepare, Parent, NULL); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); // pthread_atforkشתEXITǩ + + // g_testAtforkCount1ʾ׼ʼִfork + g_testAtforkCount++; + + // һ̵ִ̣߳߳кDoit + err = pthread_create(&tid, NULL, Doit, NULL); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT); // pthread_createʧܣתEXITǩ + + // õǰ߳1룬ȷ̺߳߳㹻ʱʵִн׶Ρ + nanosleep(&ts, NULL); + + // ִforkϵͳãһ½̡ + pid = fork(); + ICUNIT_GOTO_EQUAL(g_testAtforkPrepare, 1, g_testAtforkPrepare, EXIT); // ȷforkPrepareѾá + + if (pid == 0) { // ӽִеĴ롣 + // Doit1ӽ̽ڴִУ2롣 + Doit1(NULL); + exit(10); // 10ʾӽ̵˳״̬ + } + + // pidֵǷϷȷforkɹpidᳬ100000 + ICUNIT_GOTO_WITHIN_EQUAL(pid, 0, 100000, pid, EXIT_WAIT); + + // ȷ̵Parentg_testAtforkParent + ICUNIT_GOTO_EQUAL(g_testAtforkParent, 1, g_testAtforkParent, EXIT_WAIT); + + // ȴ߳̽ + err = pthread_join(tid, NULL); + ICUNIT_GOTO_EQUAL(err, 0, err, EXIT_WAIT); // pthread_joinʧܣתEXIT_WAITǩ + + // ȴӽ̽ȡ˳״̬ + err = waitpid(pid, &status, 0); + status = WEXITSTATUS(status); // ȡӽ̵˳״̬ + ICUNIT_GOTO_EQUAL(err, pid, err, EXIT); // waitpidֵǷpidһ¡ + ICUNIT_GOTO_EQUAL(status, 10, status, EXIT); // ȷӽ̵˳״̬10 + +EXIT: + return NULL; // NULL + +EXIT_WAIT: + // EXIT_WAITǩʾҪȴӽ̵Ľֹʬ̡ + (void)waitpid(pid, 0, 0); + return NULL; +} + +static int Testcase(void) +{ + int ret; + pthread_t newPthread; + int curThreadPri, curThreadPolicy; + pthread_attr_t a = { 0 }; + struct sched_param param = { 0 }; + + ret = pthread_getschedparam(pthread_self(), &curThreadPolicy, ¶m); + ICUNIT_ASSERT_EQUAL(ret, 0, -ret); + + curThreadPri = param.sched_priority; + + ret = pthread_attr_init(&a); + pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED); + param.sched_priority = curThreadPri + 2; // 2, adjust the priority. + pthread_attr_setschedparam(&a, ¶m); + ret = pthread_create(&newPthread, &a, PthreadAtforkTest, 0); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newPthread, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return 0; +} + +void ItTestPthreadAtfork002(void) +{ + TEST_ADD_CASE("IT_PTHREAD_ATFORK_002", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION); +} diff --git a/pthread_cond_test_001.cpp b/pthread_cond_test_001.cpp new file mode 100644 index 0000000..9de16fc --- /dev/null +++ b/pthread_cond_test_001.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "it_pthread_test.h" + +static pthread_mutex_t g_pthreadMuxTest1; +static pthread_cond_t g_pthdCondTest1; + +static void *PthreadF01(void *t) +{ + int rc; + + rc = pthread_mutex_lock(&g_pthreadMuxTest1); // Իȡ g_pthreadMuxTest1 + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); // ȡʧܣת EXITȷֵΪ0ʾɹȡ + + g_testCount++; // g_testCountʾִ߳ + LosTaskDelay(100); // ʱ 100ģ߳ڼijЩ I/O ȣ + ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // ȷʱ g_testCount 2ʾִ߳ймֵȷ + g_testCount++; // g_testCountΪ׼ + + rc = pthread_cond_wait(&g_pthdCondTest1, &g_pthreadMuxTest1); // ͷŻȴ g_pthdCondTest1 + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); // ȷȴĵûгֵΪ0ʾɹȴ + + ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); // ȷʱ g_testCount ֵΪ 5ʾ߳ͬȷ + rc = pthread_mutex_unlock(&g_pthreadMuxTest1); // ͷŻ̲߳Դ + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); // ȷͷûгֵΪ0ʾɹͷ + +EXIT: + return NULL; // ִ߳ϣ NULL +} + + +static void *PthreadF02(void *t) +{ + int i; + int rc; + + ICUNIT_GOTO_EQUAL(g_testCount, 1, g_testCount, EXIT); // ȷʱ g_testCount Ϊ 1ʾ߳ͬȷ + g_testCount++; // g_testCountΪ׼ + rc = pthread_mutex_lock(&g_pthreadMuxTest1); // ȡ g_pthreadMuxTest1 + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); // ȷȡûг + + ICUNIT_GOTO_EQUAL(g_testCount, 3, g_testCount, EXIT); // ȷʱ g_testCount 3ʾִͬеȷ + g_testCount++; // g_testCountʾ̲߳ + + rc = pthread_cond_signal(&g_pthdCondTest1); // ѵȴ g_pthdCondTest1 ߳ + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); // ȷѲɹֵӦΪ0 + + ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT); // ȷʱ g_testCount ֵΪ 4ʾ߳ͬȷ + g_testCount++; // g_testCountΪ׼ + + rc = pthread_mutex_unlock(&g_pthreadMuxTest1); // ͷŻ̷߳ʹԴ + ICUNIT_GOTO_EQUAL(rc, 0, rc, EXIT); // ȷͷûг + + LosTaskDelay(2); // ʱ 2ִ߳еʱȷԽȶ + +EXIT: + pthread_exit(NULL); // ִ߳ϣ˳ +} +static unsigned int TestCase(void) +{ + int i; // ѭ + long t1 = 1; // ߳1IJ t1 + long t2 = 2; // ߳2IJ t2 + int rc; // ڴ洢õķֵǷɹ + pthread_t threads[3]; // һ飬3ֻ̣̣߳߳01ΪʼʱԤռ + pthread_attr_t attr; // ߳Ա̵߳ԣڴ˴δþԣ + const int loopNum = 2; // ̵߳ȴյĴ + + g_testCount = 0; // ʼȫֱ g_testCountΪ0ʾ߳ͬijʼ״̬ + pthread_mutex_init(&g_pthreadMuxTest1, NULL); // ʼ g_pthreadMuxTest1 + pthread_cond_init(&g_pthdCondTest1, NULL); // ʼ g_pthdCondTest1 + + rc = pthread_create(&threads[0], NULL, PthreadF01, (void *)t1); // ߳0ִ PthreadF01 t1 Ϊ + ICUNIT_ASSERT_EQUAL(rc, 0, rc); // ȷ̴߳ɹֵӦΪ0 + + rc = pthread_create(&threads[1], NULL, PthreadF02, (void *)t2); // ߳1ִ PthreadF02 t2 Ϊ + ICUNIT_ASSERT_EQUAL(rc, 0, rc); // ȷ̴߳ɹֵӦΪ0 + + // ̵߳ȴ̵ִ߳н + for (i = 0; i < loopNum; i++) { + rc = pthread_join(threads[i], NULL); // ȴ߳ i ִϲԴ + ICUNIT_ASSERT_EQUAL(rc, 0, rc); // ȷ̼߳ɹֵӦΪ0 + } + + rc = pthread_attr_destroy(&attr); // ߳ԶͷԴ + ICUNIT_ASSERT_EQUAL(rc, 0, rc); // ȷٲɹ + + rc = pthread_mutex_destroy(&g_pthreadMuxTest1); // ٻͷԴ + ICUNIT_ASSERT_EQUAL(rc, 0, rc); // ȷٲɹ + rc = pthread_cond_destroy(&g_pthdCondTest1); // ͷԴ + ICUNIT_ASSERT_EQUAL(rc, 0, rc); // ȷٲɹ + + return 0; // 0ʾִ +} + + +void ItTestPthreadCond001(void) +{ + TEST_ADD_CASE("IT_POSIX_PTHREAD_COND_001", TestCase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +}