Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler doesn't activate sleeping threads on native_posix #30384

Closed
Tehieh opened this issue Dec 2, 2020 · 2 comments
Closed

Scheduler doesn't activate sleeping threads on native_posix #30384

Tehieh opened this issue Dec 2, 2020 · 2 comments
Assignees
Labels
area: native port Host native arch port (native_sim)

Comments

@Tehieh
Copy link

Tehieh commented Dec 2, 2020

Describe the bug
I have the following code built to run as a native_posix application:

#include <kernel.h>
#include <iostream>

constexpr int kStackSize = 1024;
K_THREAD_STACK_DEFINE(thread_stack, kStackSize);

bool _dummy_running = true;
void DummyThread(void*, void*, void*) {
  while(_dummy_running) {
    k_yield();
  }
}

void main(void)
{
  std::cout << "Create the thread." << std::endl;  
  struct k_thread dummy_thread;
  k_tid_t ret = k_thread_create(&dummy_thread, thread_stack, K_THREAD_STACK_SIZEOF(thread_stack), DummyThread, NULL, NULL, NULL, 1, 0, K_NO_WAIT);
  
  std::cout << "About to sleep." << std::endl;
  k_msleep(10);
  std::cout << "Finished sleeping." << std::endl;
  
  _dummy_running = false;
  k_thread_join(&dummy_thread, K_FOREVER);
  std::cout << "Exiting." << std::endl;
}

The code stops on the k_msleep(10); and has the following output:

*** Booting Zephyr OS build zephyr-v2.4.0-1789-g47ebde30b9ea  ***
Create the thread.
About to sleep.

Expected behavior
The code reaches the line to std::cout << "Exiting." << std::endl;

Environment (please complete the following information):

  • OS: Linux, application running inside a docker container
@Tehieh Tehieh added the bug The issue is a bug, or the PR is fixing a bug label Dec 2, 2020
@carlescufi carlescufi added the area: native port Host native arch port (native_sim) label Dec 2, 2020
@aescolar
Copy link
Member

aescolar commented Dec 2, 2020

@Tehieh That while loop is an infinite loop in that case. You need to be aware that in native_posix, code executes in 0 simulated time. So the code calls k_yield(), there is nothing to yield to, and continues looping, all in zero time.

You need to do something that causes it to spend time on that while loop. For example a k_busy_wait(some_time);

See https://docs.zephyrproject.org/latest/boards/posix/native_posix/doc/index.html#important-limitations

@aescolar aescolar added question and removed bug The issue is a bug, or the PR is fixing a bug labels Dec 2, 2020
@aescolar
Copy link
Member

aescolar commented Dec 5, 2020

Closing assuming the issue has been clarified with the previous answer. If that is not the case, please reopen.

@aescolar aescolar closed this as completed Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: native port Host native arch port (native_sim)
Projects
None yet
Development

No branches or pull requests

3 participants