mardi 1 mars 2016

Inter thread communication

Here is my simple code, I want to get in the console_task, the value of the variable i in the dialer_task... without using a global variable.

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <thread>
#include "console.hpp"

using namespace std;

void console_task(){
    console();
}

void dialer_task(){
    int i=0;
    while (1) {
        printf("LOOP %d\n",i);
        i++;
        sleep(5);
    }
}

int main()
{
    thread t1(console_task);
    thread t2(dialer_task);

    t1.join();
    t2.join();
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire