mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
freertos: Fixes deadlock in pthread_once for init_routines calling pthread_once
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "unity.h"
|
||||
|
||||
#if __GTHREADS && __GTHREADS_CXX0X
|
||||
@@ -61,7 +63,7 @@ static void thread_main()
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("pthread CXX", "[pthread]")
|
||||
TEST_CASE("pthread C++", "[pthread]")
|
||||
{
|
||||
global_sp.reset(new int(1));
|
||||
|
||||
@@ -85,16 +87,32 @@ TEST_CASE("pthread CXX", "[pthread]")
|
||||
}
|
||||
}
|
||||
|
||||
static void task_test_sandbox(void *ignore) {
|
||||
static void task_test_sandbox(void *arg)
|
||||
{
|
||||
bool *running = (bool *)arg;
|
||||
|
||||
ESP_LOGI(TAG, "About to create a string stream");
|
||||
std::stringstream ss;
|
||||
ESP_LOGI(TAG, "About to write to string stream");
|
||||
ss << "Hello World!";
|
||||
ESP_LOGI(TAG, "About to extract from stringstream");
|
||||
ESP_LOGI(TAG, "Text: %s", ss.str().c_str());
|
||||
|
||||
if (running) {
|
||||
*running = false;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("pthread CXX 2", "[pthread]")
|
||||
TEST_CASE("pthread mix C/C++", "[pthread]")
|
||||
{
|
||||
bool running = true;
|
||||
|
||||
std::thread t1(task_test_sandbox, (void *)NULL);
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&task_test_sandbox, "task_test_sandbox", 2048, &running, 5, NULL, 0);
|
||||
while (running) {
|
||||
vTaskDelay(1);
|
||||
}
|
||||
if (t1.joinable()) {
|
||||
std::cout << "Join thread " << std::hex << t1.get_id() << std::endl;
|
||||
t1.join();
|
||||
|
Reference in New Issue
Block a user