2
A
回答
0
我使用這個C代碼爲FPGA做上下文切換。如果你覺得它有用,並希望得到更多的周圍代碼,只需問我。
/*
* threadswitch - change thread
*
* The thread stack-pointer is supplied as a parameter.
* The old thread's stack-pointer value is saved to the array
* thread_info_array, and a new thread is selected from the array.
* The stack pointer of the new thread is returned.
*/
unsigned int * threadswitch(unsigned int * old_sp)
{
unsigned int * new_sp;
number_of_thread_switches += 1; /* Increase thread-switch counter. */
/* Print line 1 of an informational message. */
printf("\nPerforming thread-switch number %d. The system has been running for %d ticks.\n",
number_of_thread_switches,
get_internal_globaltime());
/* Save the stack pointer of the old thread. */
thread_info_array[ currently_running_thread ].thread_sp = old_sp;
/* Print part 1 of a message saying which threads are involved this time. */
printf("Switching from thread-ID %d ",
thread_info_array[ currently_running_thread ].thread_id);
/* Perform the scheduling decision (round-robin). */
currently_running_thread += 1;
if(currently_running_thread >= current_thread_count)
{
currently_running_thread = 0;
}
/* Print part 2 of the informational message. */
printf("to thread-ID %d.\n",
thread_info_array[ currently_running_thread ].thread_id);
/* Get the stack pointer of the new thread. */
new_sp = thread_info_array[ currently_running_thread ].thread_sp;
/* Return. */
return(new_sp);
}
+0
謝謝,但你使用POSIX標準? – khaledrmse
相關問題
- 1. 線程之間的上下文切換
- 2. 在執行兩個函數上下文之間切換
- 3. 進程中線程之間的上下文切換
- 4. 線程上下文切換vs進程上下文切換
- 5. 兩個線程之間的上下文切換問題
- 6. 如何在兩個OpenGL之間切換上下文
- 7. 從進程上下文切換切換線程上下文有多好?
- 8. 強制線程上下文切換
- 9. 上下文切換多線程
- 10. 多線程:上下文切換
- 11. 使用SIGALRM切換線程上下文
- 12. 線程和上下文切換C++
- 13. 在Linux中的兩個進程之間的上下文切換
- 14. Go如何決定何時在goroutine之間進行上下文切換?
- 15. 如何在內核模塊線程中切換上下文?
- 16. 如何在java多線程中實現上下文切換
- 17. 阻止調度程序在Java中執行上下文切換
- 18. 如何在不發生上下文切換的情況下在線程中執行2個連續的命令?
- 19. 如何在鎖定端口時在線程之間切換?
- 20. 調度程序和上下文切換器之間的區別?
- 21. java線程之間的切換控制
- 22. 如何在另一個線程之間切換視圖?
- 23. 如何在android中的多個線程之間切換
- 24. 如何估計線程上下文切換開銷?
- 25. spinlocked線程如何避免上下文切換的開銷?
- 26. python如何處理線程鎖定/上下文切換?
- 27. 如何使用SFML 2.2切換OpenGL上下文的線程?
- 28. Powershell腳本:在混合Exchange on-prem和在線之間切換上下文
- 29. POSIX線程在HP-UX和Solaris 10之間的行爲不同
- 30. 如何防止在上下文線程CompletableFuture#whenComplete執行
上下文切換完全屬於內核,用戶空間應用程序沒有與它的bussines。 – Tsyvarev