c - Start of thread changes already set global variable -
i have ran strange behavior of code, basic flow of code is
main ()
parses file , sets global variables accordingly.. such as
int frame_size, version; typedef struct//file parsing variables { int frame, int version; } configuration; ***//the function init_parse calls*** static int handler(void* user, const char* section, const char* name, const char* value) { configuration* pconfig = (configuration*)user; #define match(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0 if (match("protocol", "version")) { pconfig->version = atoi(value); } else if (match("basic", "frames")) { pconfig->frames= atoi(value); frame_size=pconfig->frames; } else { return 0; /* unknown section/name, error */ } return 1; } main (){ configuration config; if (ini_parse("test.ini", handler, &config) < 0) { printf("can't load 'test.ini'\n"); getchar(); iret = pthread_create(&hthread,null, pcapreader, null); if(iret) { fprintf(stderr,"error - pthread_create() return code: %d\n",iret); exit(exit_failure); } }
now, line followed main()
's parsing line, seems set, thread started , value frame_size changes 6345720:/
i have double checked code possible replicated variable. thread uses frame_size
in loop check limit.
the problem initialization, once initialized, worked charm :)
Comments
Post a Comment