nuttx/sched
chao an b9b615b425 sched/pthread: fix race condition on pthread_cond_wait()
pthread_cond_wait() should be an atomic operation in the mutex lock/unlock.
Since the sched_lock() has been wrongly deleted in the previous commit,
the context switch will occurred after the mutex was unlocked:

--------------------------------------------------------------------
  Task1(Priority 100)             |      Task2(Priority 101)
                                  |
  pthread_mutex_lock(mutex);      |
  |                               |
  pthread_cond_wait(cond, mutex)  |
  |  |                            |
  |  |                            |
  |  ->enter_critical_section()   |
  |  ->pthread_mutex_give(mutex)  | ----> pthread_mutex_lock(mutex);    // contex switch to high priority task
  |                               |       pthread_cond_signal(cond);    // signal before wait
  |                               | <---- pthread_mutex_unlock(mutex);  // switch back to original task
  |  ->pthread_sem_take(cond->sem)|                                     // try to wait the signal, Deadlock.
  |  ->leave_critical_section()   |
  |
  |  ->pthread_mutex_take(mutex)  |
  |                               |
  pthread_mutex_lock(mutex);      |
---------------------------------------------------------------------

This PR will bring back sched_lock()/sched_unlock() to avoid context switch to ensure atomicity

Signed-off-by: chao an <anchao@xiaomi.com>
2023-06-28 02:25:05 +08:00
..
addrenv sched/addrenv.c: Implement re-entrancy for addrenv_select() 2023-04-25 14:33:19 +02:00
clock clock: Move the content of include/nuttx/time.h to include/nuttx/clock.h 2023-06-26 19:14:08 +03:00
environ Replace all sprintf with snprintf 2023-05-08 09:57:01 +02:00
group sched/group: Ensure that the setting of tg_members if safe in SMP 2023-06-15 22:24:00 +08:00
init mm/kmm_map: Add support to dynamically map pages into kernel virtual memory 2023-06-02 10:50:26 +08:00
irq sched/irq: optimizing IRQMONITOR, move up_perf_convert to irq_procfs 2023-04-25 09:58:43 +08:00
misc sched/assert: Change show_xxx to dump_xxx 2023-06-22 23:26:56 +03:00
module Indent the define statement by two spaces 2023-05-21 09:52:08 -03:00
mqueue Indent the define statement by two spaces 2023-05-21 09:52:08 -03:00
paging sched/paging: add FAR in paging worker 2023-03-26 09:23:50 -06:00
pthread sched/pthread: fix race condition on pthread_cond_wait() 2023-06-28 02:25:05 +08:00
sched sched/sched/sched_idletask: fix typo 2023-06-19 10:51:23 +02:00
semaphore semaphore: Optimize priority inheritance with only one holder 2023-06-17 08:26:46 +03:00
signal style: remove extra spaces and align parameters 2023-06-11 12:55:29 +08:00
task sched: Remove the unnecessary cast from pid_t to int 2023-06-19 11:37:34 +03:00
timer sched/getpid: replace syscall getpid/tid/ppid() to kernel version 2023-02-02 10:33:01 +08:00
tls sched/group: fix task info heap-use-after-free 2023-01-11 01:53:59 +08:00
wdog arch/arm64: the arm64 perf interface supports pmu 2023-04-10 16:23:49 -03:00
wqueue sched/wqueue: fix issue about worker can't wake up thread before work_thread running 2023-04-19 02:50:04 +08:00
Kconfig sched/tls: remove PTHREAD_CLEANUP from Kconfig 2023-06-14 12:00:48 +08:00
Makefile group/group_addrenv: Move address environment from group -> tcb 2023-02-08 02:51:23 +08:00