Thread priority preemption experiment [RT-thread Study Notes 3], rt-Thread Study Notes
At the same time, the thread is in the ready state and runs first with a higher priority.
When a high-priority task is ready, the low-priority task gives way to the CPU, so that the high-priority task is executed first.
Create two task functions:
// Preemptible void thread1_entry (void * parameter) {rt_uint32_t count = 0; while (1) {for (; count ++) {rt_thread_delay (3 * RT_TICK_PER_SECOND ); // output rt_kprintf ("count = % d \ n", count) ;}} void thread2_entry (void * parameter) {rt_tick_t tick; rt_uint32_t I = 0; for (I = 0; I ++) {tick = rt_tick_get (); rt_thread_delay (RT_TICK_PER_SECOND); // The rt_kprintf ("tick = % d \ n ", tick );}}
Start them:
Void rt_thread_test (void) {// thread preemption experiment result = rt_thread_init (& thread1, "thread1", thread1_entry, RT_NULL, thread1_stack, 10); if (result = RT_EOK) {rt_thread_startup (& thread1);} if (RT_EOK = rt_thread_init (& thread2, "thread2", thread2_entry, RT_NULL, thread2_stack, 512,10, 10 )) {rt_thread_startup (& thread2 );}}
Because of the higher priority, thread1 takes the lead to get the execution, and then it calls the delay. The time is three system tick, so thread2 gets the execution. You can find a rule in the printed results. After thread2 is printed twice and thread1 is printed once, then thread2 prints thread1 once every three times. By analyzing the entry program of two threads, we can find that thread2 will actually receive three execution opportunities in the latency of three tick systems in thread1, however, it is clear that the third execution of thread2 does not end in the first delay of thread1. After the third delay, thread2 should execute the third print count, however, because the latency of thread1 is also over at this time, and its priority is higher than that of thread2, so it preemptible the execution of thread2 and started to execute. When thread1 enters the latency again, the printing of the previously preemptible thread2 can continue, and after two system tick latencies and two print counts, after the third system tick is finished, the latency of thread1 is terminated, and thread1 is re-preemptible for execution. Therefore, thread2 executes Three print counts before thread1 printing.
Java multithreading problems? -Function Threadsleep (3 );
Simultaneous multi-thread Simultaneous multithreading (SMT. SMT allows multiple threads on the same processor to run concurrently and share the execution resources of the processor through the structure status on the replication processor, allows you to process excessive data volumes in a wide-emission or out-of-order manner to the maximum extent, improve the utilization of processor computing components, and reduce the access memory latency caused by data-related or Cache miss. When there are no threads available, the SMT processor is almost the same as the traditional Wide-emission processor. The most attractive thing about SMT is that it only needs to change the design of the core of the processor in a small scale and can significantly improve performance without additional costs. Multithreading technology can prepare more data to be processed for the high-speed computing core, reducing the idle time of the computing core. This is undoubtedly very attractive for low-end desktop systems. Intel starts from 3.06 GHz Pentium 4 and all processors will support SMT Technology.
C ++ data type conversion creation thread, CreateThread parameter 3 I want to pass a CString type pointer, how to convert CString to LPVOID
I think the problem with your algorithm is that
The main thread exits the function after CreateThread, causing the CString str to be destructed. At this time, the created sub-thread cannot obtain the correct value when getting the lpParameter.
We recommend that you use global objects or dynamically generate objects on the stack.