Bonjour,
Qui peut m'aider a corriger ce code. Le probleme que seul le 3 eme thread fonctionne et ce pendant juste quelques instants !!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <sched.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#define PTU 2000           // 2ms
#define HIGHEST_PRIORITY 99
typedef struct milcan_data
{
	int sync ;
	int slave_ID;
}milcan_data;
 
struct milcan_data milcan_arg;
 
void *slave_func(void *slave_data)
{
	int j;
	struct milcan_data * slave_signals= (struct milcan_data *)slave_data;
	while(1)
	{
			usleep(2000000+(100*(slave_signals->slave_ID)));
			slave_signals->sync++;
			fprintf(stdout,"slave (%d) is talking the current sync is (%d) \n",slave_signals->slave_ID,slave_signals->sync);
	}
	return(NULL);
}
 
int main ()
{
	int val,i,j;
	int err;
	struct sched_param param_processus;
	struct sched_param param_slave_thr ;
	pthread_attr_t slave_attr;
	/////////////////     AFFECTATION PRIORITE TEMPS REEL FIFO
	param_processus.sched_priority = HIGHEST_PRIORITY;
	if (sched_setscheduler(0, SCHED_FIFO, &param_processus) != 0)
	{
		perror("processus sched_setscheduler");
		exit(EXIT_FAILURE);
	}
	/////////////////     PREPARATION DES ATTRIBUTS DU SLAVE_THREAD
	pthread_attr_init(&slave_attr);
 
	if ((err=pthread_attr_setschedpolicy(&slave_attr,SCHED_RR))!=0)
	{
		fprintf(stderr,"setschedpolicy slave thread: %s\n",strerror(err));
		exit(EXIT_FAILURE);
	}
	if ((err=pthread_attr_setinheritsched(&slave_attr,PTHREAD_EXPLICIT_SCHED))!=0)
	{
		fprintf(stderr,"setinheritshed slave thread: %s\n",strerror(err));
		exit(EXIT_FAILURE);
	}
 
	param_slave_thr.sched_priority = HIGHEST_PRIORITY;
 
	if ((err=pthread_attr_setschedparam(&slave_attr,&param_slave_thr))!=0)
	{
		fprintf(stderr,"setschedparam slave thread: %s\n",strerror(err));
		exit(EXIT_FAILURE);
	}
	///////////////////////////////////////////////////// PREPARATION MILCAN_DATA
	pthread_t slave_thr[3];
	milcan_arg.sync = 0;
 
	/////////////////////   EXECUTION DES THREAD
	for ( i=0;i<3;i++)
	{
		milcan_arg.slave_ID=i+1;
 
		if((err=pthread_create(&slave_thr[i],NULL,slave_func,&milcan_arg)!=0))
		{	
			fprintf(stderr,"can't create slave thread %s \n",strerror(err));
			exit(EXIT_FAILURE);
		}
	}
	// ATTENTE DE TOUS LES THREAD
	for ( i=0;i<3;i++)
	{
		pthread_join(slave_thr[i], NULL);	
	}
	return 0;
 
 
 
 
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[makavelli@fibonacci my_RT_codes ]$ gcc -w  -lpthread -lrt -o testtaksirkrayem test_sched.c -Wall
[makavelli@fibonacci my_RT_codes ]$ taskset -c 3 sudo ./testtaksirkrayem
slave (3) is talking the current sync is (1) 
slave (3) is talking the current sync is (2) 
slave (3) is talking the current sync is (3) 
slave (3) is talking the current sync is (4) 
slave (3) is talking the current sync is (5) 
slave (3) is talking the current sync is (6) 
slave (3) is talking the current sync is (7) 
slave (3) is talking the current sync is (8) 
slave (3) is talking the current sync is (9) 
slave (3) is talking the current sync is (10) 
slave (3) is talking the current sync is (11) 
slave (3) is talking the current sync is (12) 
slave (3) is talking the current sync is (13) 
slave (3) is talking the current sync is (14) 
slave (3) is talking the current sync is (15) 
^C[makavelli@fibonacci my_RT_codes ]$ ^C
[makavelli@fibonacci my_RT_codes ]$