[RTT routine exercises] 1.3 thread out

Source: Internet
Author: User

RTT supports the same priority, but ucoⅱ does not.

If a thread does not call the rt-thread_delay () to let out the scheduler, it will always run, and other threads will always be in the ready state.

A thread with the same priority defines the longest time slice for a single run during initialization or creation, and forces the thread to exit the scheduler.

Here, usert_thread_yield();You can also give way to the dispatcher.

# Include <rtthread. h> rt_thread_t tid1 = rt_null; rt_thread_t tid2 = rt_null; static void thread1_entry (void * parameter) {rt_uint32_t COUNT = 0; while (1) {rt_kprintf ("thread1: count = % d \ n ", Count ++); rt_thread_yield () ;}} static void thread2_entry (void * parameter) {rt_uint32_t COUNT = 0; while (1) {rt_thread_yield (); rt_kprintf ("thread2: Count = % d \ n", Count ++) ;}}/* must have the same priority, otherwise, a thread is ready after the scheduler is released. The queue, which has a higher priority than the other thread, will continue to run, making the other thread unable to run. */INT rt_application_init () {tid1 = rt_thread_create ("T1", thread1_entry, rt_null, 512, 6, 10); If (tid1! = Rt_null) rt_thread_startup (tid1); tid2 = rt_thread_create ("T2", thread2_entry, rt_null, 512, 6, 10); If (tid2! = Rt_null) rt_thread_startup (tid2); Return 0 ;}/*@}*/

Output result:

\ | /- RT - Thread Operating System/ | \ 1.1.0 build Aug 10 20122006 - 2012 Copyright by rt-thread teamthread1: count = 0thread1: count = 1thread2: count = 0thread1: count = 2thread2: count = 1thread1: count = 3thread2: count = 2thread1: count = 4thread2: count = 3thread2: count = 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.