hi, thanks for the course, i’m self-studying this course online and hope can get some help.
i know in order to implement cv_wait, we need to release the lock (which was passed in), then make the ‘thread’ sleep, then when the thread been wake up, acquire the lock again.
i was plan to implement CV using wchan, however
void wchan_sleep(struct wchan *wc, struct spinlock *lk);
wechan_sleep require both a wchan AND
spinlock, do I have to initialize a spinlock inside CV or is there any quick way to make a thread sleep?
i checked the implementation of wchan_sleep, it used
thread_switch(threadstate_t newstate, struct wchan *wc, struct spinlock *lk)
inside, however, still spinlock required.
there are some very old code online that use
wchan_sleep ( which does not require a spinlock) and
thread_sleep (but i can not find any code about it).
any help would be greatly appreciated