ThreadProblem?
-
Hallo,
Also folgender Codeauszug:
for(;;) { // Make a .time file in /tmp directory for time measuring algorythm system("touch /tmp/time"); /* THREADING RULEZ THIS IS THE THREAD FOR THE TIME MEASURE!!! */ // Here comes the threading p4rtz pthread_t thread1, thread2; char *message1 = argv[2]; int iret1; // Create the thread and link them with threadf function iret1 = pthread_create( &thread1, NULL, threadf, (void*) message1); // Join them pthread_join( thread1, NULL); cout << "Hello From Main"; } void *threadf( void *ptr ) { // The variable argument will get the time to wait in seconds // Basically it's just the argv[2]! //char *argument; //argument = (char *) ptr; //int timewait = atoi(argument); // We are in the threaded function // Time to wait goes here sleep(10); system ("rm -rf /tmp/time"); }
Sollte jetzt eigentlich nich folgendes passieren:
Der Thread wird gestartet.
Es wird auf dem Bildschirm "Hello From Main" angezeigt.
Der Thread wartet derweil parallel die 10 Sekunden ab und löscht dann /tmp/time !Was passiert ist:
Es wird 10 Sekunden gewartet. /tmp/time wird gelöscht.
Es wird "Hello From Main" angezeigt.
Also ob es eine normale Funktion ist.compilieren tu ich mit:
# g++ -pthread test_thread.cpp -o thread.outLG und Danke für die Hilfe
-
Entschuldigung die Unendlich Schleife
for(;;)
{}
gehört natürlich weg
-
c00l3 k0mment4r3
-
// schrieb:
c00l3 k0mment4r3
Spar dir solche Aussagen, wenn du nicht helfen kannst/willst hör auf zu spammen! Danke!
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum Linux/Unix verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Die Ausgabe ist erst nach dem pthread_join. Das pthread_join wartet bis zum Ende des Threads.