Thông tin tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P7:Although the history of embedded systems is relatively short, 1 the advances andsuccesses of this fi eld have been profound. Embedded systems are found in a vast array ofapplications such as consumer electronics, “ smart ” devices, communication equipment,automobiles, desktop computers, and medical equipment.
Nội dung trích xuất từ tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P7 Mutual Exclusion Challenges and Considerations 119 047 048 /****************************************************/ 049 /* Application Definitions */ 050 /****************************************************/ 051 052 /* Define what the initial system looks like. */ 053 054 void tx_application_define(void *first_unused_memory) 055 { 056 057 058 /* Put system definitions here, 059 e.g., thread and mutex creates */ 060 061 /* Create the Speedy_Thread. */ 062 tx_thread_create(&Speedy_Thread, “Speedy_Thread”, 063 Speedy_Thread_entry, 0, 064 stack_speedy, STACK_SIZE, 065 5, 5, TX_NO_TIME_SLICE, TX_AUTO_START); 066 067 /* Create the Slow_Thread */ 068 tx_thread_create(&Slow_Thread, “Slow_Thread”, 069 Slow_Thread_entry, 1, 070 stack_slow, STACK_SIZE, 071 15, 15, TX_NO_TIME_SLICE, TX_AUTO_START); 072 073 /* Create the mutex used by both threads */ 074 tx_mutex_create(&my_mutex, “my_mutex”, TX_NO_INHERIT); 075 076 } 077 078 079 /****************************************************/ 080 /* Function Definitions */ 081 /****************************************************/ 082 083 /* Define the activities for the Speedy_Thread */ 084 085 void Speedy_Thread_entry(ULONG thread_input) w w w.ne w nespress.comPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 120 Chapter 8 086 { 087 UINT status; 088 ULONG current_time; 089 090 while(1) 091 { 092 093 /* Activity 1: 2 timer-ticks. */ 094 tx_thread_sleep(2); 095 096 /* Activity 2: 5 timer-ticks *** critical section *** 097 Get the mutex with suspension. */ 098 099 status tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 100 if (status ! TX_SUCCESS) break; /* Check status */ 101 102 tx_thread_sleep(5); 103 104 /* Release the mutex. */ 105 status tx_mutex_put(&my_mutex); 106 if (status ! TX_SUCCESS) break; /* Check status */ 107 108 /* Activity 3: 4 timer-ticks. */ 109 tx_thread_sleep(4); 110 111 /* Activity 4: 3 timer-ticks *** critical section *** 112 Get the mutex with suspension. */ 113 114 status tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 115 if (status ! TX_SUCCESS) break; /* Check status */ 116 117 tx_thread_sleep(3); 118 119 /* Release the mutex. */ 120 status tx_mutex_put(&my_mutex); 121 if (status ! TX_SUCCESS) break; /* Check status */ 122 123 current_time tx_time_get(); 124 printf(“Current Time: %lu Speedy_Thread finished cycle...
”, w ww. n e w n e s p r e s s .c o mPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Mutual Exclusion Challenges and Considerations 121 125 current_time); 126 127 } 128 } 129 130 /****************************************************/ 131 132 /* Define the activities for the Slow_Thread */ 133 134 void Slow_Thread_entry(ULONG thread_input) 135 { 136 UINT status; 137 ULONG current_time; 138 139 while(1) 140 { 141 142 /* Activity 5: 12 timer-ticks *** critical section *** 143 Get the mutex with suspension. */ 144 145 status tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 146 if (status ! TX_SUCCESS) break; /* Check status */ 147 148 tx_thread_sleep(12); 149 150 /* Release the mutex. */ 151 status tx_mutex_put(&my_mutex); 152 if (status ! TX_SUCCESS) break; /* Check status */ 153 154 /* Activity 6: 8 timer-ticks. */ 155 tx_thread_sleep(8); 156 157 /* Activity 7: 11 timer-ticks *** critical section *** 158 Get the mutex with suspension. */ 159 160 status tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 161 if (status ! TX_SUCCESS) break; /* Check status */ 162 163 tx_thread_sleep(11); 164 w w w.ne w nespress.comPlease purchas ...