forked from espressif/esp-idf
pthread: Fix race conditions in existing pthread UTs
This commit is contained in:
@@ -12,6 +12,7 @@ static void *compute_square(void *arg)
|
|||||||
{
|
{
|
||||||
int *num = (int *) arg;
|
int *num = (int *) arg;
|
||||||
*num = (*num) * (*num);
|
*num = (*num) * (*num);
|
||||||
|
vTaskDelay(2); // ensure the test task has time to continue execution
|
||||||
pthread_exit((void *) num);
|
pthread_exit((void *) num);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -80,14 +80,16 @@ TEST_CASE("pthread C++", "[pthread]")
|
|||||||
|
|
||||||
std::thread t3(thread_main);
|
std::thread t3(thread_main);
|
||||||
std::thread t4(thread_main);
|
std::thread t4(thread_main);
|
||||||
if (t3.joinable()) {
|
TEST_ASSERT(t3.joinable());
|
||||||
|
TEST_ASSERT(t4.joinable());
|
||||||
std::cout << "Join thread " << std::hex << t3.get_id() << std::endl;
|
std::cout << "Join thread " << std::hex << t3.get_id() << std::endl;
|
||||||
t3.join();
|
t3.join();
|
||||||
}
|
|
||||||
if (t4.joinable()) {
|
|
||||||
std::cout << "Join thread " << std::hex << t4.get_id() << std::endl;
|
std::cout << "Join thread " << std::hex << t4.get_id() << std::endl;
|
||||||
t4.join();
|
t4.join();
|
||||||
}
|
|
||||||
|
// we don't know if/when t2 has finished, so delay another 2s before
|
||||||
|
// deleting the common mutexes
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
|
|
||||||
global_sp_mtx.reset(); // avoid reported leak
|
global_sp_mtx.reset(); // avoid reported leak
|
||||||
global_sp_recur_mtx.reset();
|
global_sp_recur_mtx.reset();
|
||||||
|
Reference in New Issue
Block a user