[ARM9][POSIX]Passer un élément de tableau de structure à la création d'un thread
Bonjour à tous,
je tombe sur une tuile que je n'arrive pas à comprendre :
(je compile avec arm-linux-gcc pour info)
Pour mon besoin je voudrais passer à la création de mon thread un élément de tableau de structure (donc une structure quoi, du moins pour moi)
Pour passer une structure simple, j'ai testé ça fonctionne très bien :
Code:
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
| #include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
typedef unsigned int uint32_t;
typedef unsigned short int uint16_t;
typedef unsigned char uint8_t;
typedef
enum
{
HAUT = 0,
BAS = 1,
_NB_ELTS_HAUTEUR_ // sera evalue au nombre d'elements de l'enumere (pour l'instant 2)
} hauteur_cable_t;
struct modbus
{
int lasterrno; /** value of errno after last failed C-library call */
int fd; /**< holds the socket file descriptor of the modbus connection */
//struct sockaddr_in addr; /**< holds the IP address of the modbus connection */
//modbus_exception_code_t exception; /**< modbus exception code - use modbus_exception_to_str() to get a human readable string */
};
typedef struct
{
struct modbus modbus; // TBC si struct modbus ou struct modbus *
hauteur_cable_t cable;
} modbus_cable_t;
void *hello2(void *input) {
printf("modbus.fd: %d\n", ((modbus_cable_t *)input)->modbus.fd);
printf("cable: %d\n", ((modbus_cable_t *)input)->cable);
}
int main()
{
modbus_cable_t *GAB = (modbus_cable_t *)malloc(sizeof(modbus_cable_t));
GAB->modbus.fd=1989;
GAB->cable=BAS;
pthread_t GABTHREAD ;
pthread_create(&GABTHREAD, NULL, hello2, (void *)GAB);
pthread_join(GABTHREAD, NULL);
return 0;
} |
ça me retourne bien les valeurs que j'ai mises dans le main.
mais si par exemple j'essaie quelque chose du genre :
Code:
1 2 3 4
|
modbus_cable_t * GAB2[2] ;
GAB2[0]->modbus.fd=3199 ;
GAB2[0]->cable=HAUT ; |
avec un appel du style :
Code:
1 2 3 4
|
pthread_t GABTHREAD ;
pthread_create(&GABTHREAD, NULL, hello2, (void *)GAB2[0]);
pthread_join(GABTHREAD, NULL); |
Je tombe sur un Seg Fault direct et je n'arrive pas à comprendre pourquoi, d'autant que si je fais un
Code:
modbus_cable_t * mon_element_de_tableau = &GAB2[0]
et que je passe mon_element_de_tableau dans le pthread_create, ça fonctionne très bien 8O8O8O
:arf::koi::koi::koi:
Quelqu'un peut-il éclairer ma lanterne sur pourquoi ça ne marche pas, peut-être que je ne l'écris pas correctement, mais j'ai également testé de passer en tableau dynamique plutôt que statique, rien n'y fait ça ne fonctionne pas mieux :'(