Hi Jianwen, thread_msg does a context switch between p3 and p1 because p1 does not have a message queue. The second message from p3 causes p3 to go into a blocked state and give up control otherwise the previous message will be lost.
if in p1 a msg_queue is defined: void *thread1(void *arg) { (void) arg; msg_t msg_queue[8]; msg_init_queue(msg_queue, 8); puts("THREAD 1 start\n"); ... then thread_msg example will run as documented until the message queue is full. I hope this little explanation may help ... ciao Attilio On Thu, Mar 31, 2016 at 10:35 AM, OuyangJianwen <jianwen.ouy...@outlook.com> wrote: > Hello, > > I am a new beginner to learn RIOT. I got some question when I run the > "thread_msg" on board "SAMR21-xpro". > > For the thread1, thread2 and thread3, they have the same priority. so when > the thread3 is running, how can scheduler switch to the thread1. > > I saw these in the API: > "In case of equal priorities, the threads are scheduled in a > semi-cooperative fashion. That means that unless an interrupt happens, > threads with the same priority will only switch due to voluntary or > implicit context switches." > and > "Some functions that unblock another thread, e.g. msg_send() > <http://riot-os.org/api/group__core__msg.html#gac5347725c3d203ac72604c0ab8b7d6d8> > or mutex_unlock() > <http://riot-os.org/api/group__core__sync.html#ga05ccabe849d63b032f6317323da60187>, > can cause a thread switch, if the target had a higher priority." > > but here, all the three threads have the same priority, so according the > rule, even there is msg_send() > <http://riot-os.org/api/group__core__msg.html#gac5347725c3d203ac72604c0ab8b7d6d8>, > the thread3 should not be blocked and run forever, but it doesn't. > > Thanks for your time! > > Regards, > Jianwen OUYANG > > > > _______________________________________________ > devel mailing list > devel@riot-os.org > https://lists.riot-os.org/mailman/listinfo/devel > >
_______________________________________________ devel mailing list devel@riot-os.org https://lists.riot-os.org/mailman/listinfo/devel