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. 線程上下文切換vs進程上下文切換
- 4. 兩個線程之間的上下文切換問題
- 5. 從進程上下文切換切換線程上下文有多好?
- 6. 多線程:上下文切換
- 7. 上下文切換多線程
- 8. 使用SIGALRM切換線程上下文
- 9. 線程和上下文切換C++
- 10. 如何在java多線程中實現上下文切換
- 11. 如何在不發生上下文切換的情況下在線程中執行2個連續的命令?
- 12. 如何在鎖定端口時在線程之間切換?
- 13. 調度程序和上下文切換器之間的區別?
- 14. 如何在android中的多個線程之間切換
- 15. 如何在另一個線程之間切換視圖?
- 16. Powershell腳本:在混合Exchange on-prem和在線之間切換上下文
- 17. spinlocked線程如何避免上下文切換的開銷?
- 18. python如何處理線程鎖定/上下文切換?
- 19. 如何估計線程上下文切換開銷?
- 20. POSIX線程在HP-UX和Solaris 10之間的行爲不同
- 21. 如何防止在上下文線程CompletableFuture#whenComplete執行
- 22. 主線程的執行上下文
- 23. POSIX線程在ios上
- 24. 如何在多核處理器上完成線程的上下文切換?
- 25. 在登錄觸發器內切換執行上下文
- 26. 如何在線程之間執行健康檢查?
- 27. 如何以編程方式在macosx上執行切換用戶
- 28. 上下文切換線程正在等待
- 29. 是上下文切換進程之間不太昂貴的具有相同的可執行
- 30. 設備驅動程序IRQL和線程/上下文切換
上下文切換完全屬於內核,用戶空間應用程序沒有與它的bussines。 – Tsyvarev