Skip to content

Commit

Permalink
Merge pull request atomvm#1087 from bettio/scheduler-threads-main-sta…
Browse files Browse the repository at this point in the history
…ck-size

Fix crash in network driver by increasing threads stack size

Closes atomvm#1059

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Mar 2, 2024
2 parents e678dc0 + 80944f5 commit deda6cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `BOOTLOADER_OFFSET` was incorrect for Esp32-C6 and Esp32-S2.
- Fixed a bug that would fail to set DHCP hostname in STA+AP mode on all ESP32 platforms.
- ESP32-S3: crash in network driver caused by a smaller stack size for scheduler threads, when
calling `esp_wifi_init()`. See also issue [#1059](https://github.com/atomvm/AtomVM/issues/1059).

### Changed

Expand Down
17 changes: 16 additions & 1 deletion src/platforms/esp32/components/avm_sys/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "smp.h"

#include <sdkconfig.h>

#ifndef AVM_NO_SMP
#include <unistd.h>
#include <pthread.h>
Expand Down Expand Up @@ -97,13 +99,26 @@ void smp_scheduler_start(GlobalContext *ctx)
AVM_ABORT();
}
}

pthread_attr_t thread_attr;
if (UNLIKELY(pthread_attr_init(&thread_attr) != 0)) {
AVM_ABORT();
}
if (UNLIKELY(pthread_attr_setstacksize(&thread_attr, CONFIG_ESP_MAIN_TASK_STACK_SIZE) != 0)) {
AVM_ABORT();
}

pthread_t thread;
if (UNLIKELY(pthread_create(&thread, NULL, scheduler_thread_entry_point, ctx))) {
if (UNLIKELY(pthread_create(&thread, &thread_attr, scheduler_thread_entry_point, ctx))) {
AVM_ABORT();
}
if (UNLIKELY(pthread_detach(thread))) {
AVM_ABORT();
}

if (UNLIKELY(pthread_attr_destroy(&thread_attr) != 0)) {
AVM_ABORT();
}
}

bool smp_is_main_thread(GlobalContext *glb)
Expand Down

0 comments on commit deda6cd

Please sign in to comment.