Singleton thread function: delay(1) vs os_thread_yield()


I see that the singleton pattern uses delay(1) here vs using os_thread_yield():

I read on the docs why:

Do we know in which versions this bug is present?

@gusgonnet, I can't answer which versions but if you use delay(1), it won't matter. The delay will cause the task scheduler to move to another task for the duration of the delay which, in this case, is the same as the time slice.

Alright! Thanks Paul. While trying to understand the above (and in the docs) I asked chatGPT and it gave me a hand in connecting the dots here.

image said:

A task scheduler timeslice, also known as a time quantum or time slice, is a concept in computer multitasking and scheduling algorithms. It refers to the amount of time allocated to a task or process by the operating system scheduler before switching to another task.

In a multitasking system, the CPU time is divided into small intervals called timeslices. Each timeslice represents a fixed amount of time during which a process or task can execute. The purpose of using timeslices is to allow multiple tasks to share the CPU fairly and give the illusion of simultaneous execution.

When a task is scheduled to run, it is given a timeslice by the operating system. The task can utilize the CPU for that duration. If the task completes or yields the CPU before the timeslice expires, the scheduler selects the next task to run. If the timeslice elapses before the task completes, the scheduler interrupts the task and switches to another task.

The length of a timeslice can vary depending on the scheduling algorithm and the operating system's configuration. Shorter timeslices allow for more frequent task switching, which can improve responsiveness but may incur higher overhead due to context switching. Longer timeslices can reduce context switching overhead but may result in slower response times for interactive tasks.

Overall, the task scheduler timeslice plays a crucial role in determining how tasks or processes share CPU time and how responsive the system feels to user interactions in a multitasking environment.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.