c - C 中的线程间通信

标签 c multithreading pthreads

作为我的项目的一部分,我必须使用线程修改数值积分算法。

这大致就是传统顺序方法中发生的情况..

void Controller(struct DE)
{
    //initialization step
    for(;;)   //till the entire range has not been covered...
    {
         //compute the next time-point solution using the previously known solutions.
         NIiter();
         //then check if the result is acceptable or not and take the necessary steps...
    }
}

现在这就是我打算做的......

void Controller(struct DE)
{
    //initialization step
    for(;;)   //till the entire range has been covered...
    {
         //compute the next time using the previously known solution.
         NIiter();
         //when I have an approximate solution available..launch a thread to compute the next time-point using this approximate solution as a previous solution...something like forward pipelining...
         //then check if BOTH the results are acceptable or not and take the necessary steps...
    }
}

但我不明白如何通知我的 Controller 有一个近似的解决方案可用...以便它可以启动一个新线程...

这是我第一次接触多线程编程...所以请原谅我,如果这似乎是一个明显的问题...而且我在我的项目中使用 Pthread 库...

最佳答案

这是一个很大的话题,但这里有一些提示

  1. Worker threads - 基本上创建一堆线程并有一个任务队列。他们拿走队列中的一个并完成工作
  2. IPC - 这里有信号量、共享内存、消息传递。链接位于 page

维基百科将帮助您前进。

关于c - C 中的线程间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13217761/

相关文章:

Java 等待和通知 : IllegalMonitorStateException

c - 什么时候在 GNU C 中使用分离线程?

c - 在此 pthreaded C 程序中避免死锁的一些提示

c - 如何在源代码级别自动展开源代码中的循环?

c - TabControl 在显示溢出箭头时剪裁客户区

c# - .Net ThreadPool 线程是如何创建的?

c - c 中的 pthread 预期声明说明符或 '...' 之前的 '('

c - 如何将数字更改为 C 中的变量?

c - 我无法完美地完成这个循环

c++ - 多线程应用程序中的控制台