Skip to content

improve threading #10

@eigen-value

Description

@eigen-value

In bridge.h k_msleep calls should be substituted by k_yield
see zephyr documentation

boolean flags should be substituted by zephyr atomic_t type and accessed accordingly eg:

#include <zephyr/sys/atomic.h>

atomic_t data_ready = ATOMIC_INIT(0);
int shared_data;

// Producer thread
void producer(void) {
    shared_data = 42;
    // Use release ordering to ensure data is visible
    atomic_set(&data_ready, 1);
}

// Consumer thread
void consumer(void) {
    // Use acquire ordering to ensure we see the data
    while (atomic_get(&data_ready) == 0) {
        k_yield(); // or k_msleep(1)
    }
    // Now safe to use shared_data
    printk("Data: %d\n", shared_data);
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions