C语言中的线程间通信

时间:2012-11-04 10:29:32

标签: 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...
    }
}

但是我不明白如何通知我的控制器有一个近似的解决方案......所以它可以启动一个新的线程...

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

1 个答案:

答案 0 :(得分:1)

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

  1. Worker threads - 基本上创建一堆线程并拥有一个任务队列。他们采取其中一个队列并完成工作
  2. IPC - 这里有信号量,共享内存,消息传递。链接位于page
  3. 维基百科将帮助你。

相关问题