用C线程间通信 [英] Inter Thread Communication in C

查看:129
本文介绍了用C线程间通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As a part of my project I have to modify a Numerical Integration Algorithm using threads.

这大致就是在传统的顺序发生的方法。

This is roughly what happens in the conventional sequential approach..

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...
    }
}

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

Now this is what I intend to do....

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...
    }
}

但我不知道如何来通知我的控制器的一个近似解可...所以它可以启动一个新的线程...

But I dont understand how to notify my controller that the an approximate solution is available...so it can launch a new thread...

这是我第一次接触多线程编程...所以原谅我,如果这似乎是一个明显的question..also我使用pthread库在我的项目...

This is my first exposure to multi-threaded programming...so forgive me if this seems to be an obvious question..also I am using Pthread library in my project...

推荐答案

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

This is a vast topic but here are some pointers


  1. 工作线程 - 基本上,创建一批线程,并有一个任务队列。他们采取队列之一,做的工作

  2. IPC - 这里有信号量,共享内存,消息传递。链接是页面

  1. Worker threads - Basically create a bunch of threads and have a queue of tasks. They take one of the queue and do the job
  2. IPC - Here you have semaphores, shared memory, messaging passing. Links are on the page

维基百科将让你去。

这篇关于用C线程间通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆