Subj : Re: passing an 'int' to a thread To : comp.programming.threads From : Huub Date : Wed Jun 08 2005 07:19 am You were right. The errors were due to a linking problem. And I made a another mistake which I corrected. Now something is being passed, but it's not the correct value. Could you tell me what is being passed: task_ids or t? New code: #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include "ftapi/ftapi.h" using namespace std; using namespace ftapi; // default interface connection string device(""); ft_if_conn connection = FT_IC_LIB_USB; IfOutputs out; IfInputs inp; void *MotorDraad(void *threadid) { int *id_ptr, task_id; id_ptr = (int *)threadid; task_id = *id_ptr; cout << "Start MotorDraad" << endl; time_t start; time_t current; time(&start); try { auto_ptr fti (ftGetIfFromFactory(device, connection)); // Initialspeed = task_id FtMotorSpeed mSpeed1(task_id); cout << "Snelheid1 = " << task_id << endl; // Initialspeed = task_id FtMotorSpeed mSpeed2(task_id); cout << "Snelheid2 = " << task_id << endl; // enable all motor outputs out.data[FT_MASTER]= 0xFF; // M1: not moving out.setMotorSpeed(FT_MASTER, FT_M1, mSpeed1); // M2: forward with velocity 4 out.setMotorSpeed(FT_MASTER, FT_M2, mSpeed2); while (difftime(current,start) < 5.0) { time(¤t); fti->writeAndReadAllData(out, inp); } } // anything went wrong catch (exception &x) { cout << x.what() << endl; } } int main(int argc, char *argv[]) { cout << "Start fase 1" << endl; pthread_t threads[1]; int *task_ids[1]; int rc, t; t = 0; int snelheid = 0; cout << "1 Thread gedeclareerd" << endl; cout << "fttestextension v0.4" << endl; if (1 == argc) { /* leave device name as defined above, since no parameters given */ } else if (((2 == argc) || (3 == argc)) && (string("-l")==(argv[1]))) { if (3 == argc) device = argv[2]; connection = FT_IC_LIB_USB; } else if (((2 == argc) || (3 == argc)) && (string("-u")==(argv[1]))) { if (3 == argc) { device = argv[2]; } else { device = "/dev/usb/robointerface0"; } connection = FT_IC_USB; } else { return EXIT_FAILURE; } // now let's go! cout << "opening fischertechnik interface \"" << device << "\"" << endl; task_ids[t] = (int *) malloc(sizeof(int)); *task_ids[t] = t; while (snelheid != 8) { cin >> snelheid; cout << "Aanmaken thread" << endl; cout << "t = " << t << endl; t = snelheid; // new piece of code rc = pthread_create(&threads[t], NULL, MotorDraad, (void *)task_ids[t]); //what is passed: task_ids or t? } pthread_exit(NULL); return EXIT_SUCCESS; } // EOF Thank you for helping out. .