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