C
Wie lange habe ich darauf gewartet?...
Cooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool 390% Prozessorauslaustung!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! > 2 Ghz!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Eine Frage noch wie kann ich mit den funktionen daten austauschen, mache ich das am besten über globale Variablen oder wie?
Und noch eine () für was ist denn eigentlich
static int
nützlich?
MfG & Vielen Vielen DANK!
Achso hier der Code:
/*
pthread.c - Kind-Prozess mit der libpthread
*/
# include <stdio.h>
# include <string.h>
# include <pthread.h>
static char buffer[80] = "Can you hear me?";
void *child_function(void *text)
{
static int status;
printf("child is running.\n");
strcat(buffer, text);
status = 0;
for(;;) printf("");
pthread_exit(&status);
}
void *child_function2(void *text)
{
static int status;
printf("child is running.\n");
strcat(buffer, text);
status = 0;
for(;;) printf("");
pthread_exit(&status);
}
void *child_function3(void *text)
{
static int status;
printf("child is running.\n");
strcat(buffer, text);
status = 0;
for(;;) printf("");
pthread_exit(&status);
}
void *child_function4(void *text)
{
static int status;
printf("child is running.\n");
strcat(buffer, text);
status = 0;
for(;;) printf("");
pthread_exit(&status);
}
int main()
{
int *status_ptr;
pthread_t child_thread, child_thread2, child_thread3, child_thread4;
printf("buffer='%s'\n", buffer);
printf("running child...\n");
pthread_create(&child_thread2, NULL, &child_function2, " Yes!");
pthread_create(&child_thread3, NULL, &child_function2, " Yes!");
pthread_create(&child_thread4, NULL, &child_function2, " Yes!");
if (pthread_create(&child_thread, NULL, &child_function, " Yes!"))
{
fprintf(stderr, "pthread: pthread_create() failed.\n");
return(1);
}
if (pthread_join(child_thread, (void *)&status_ptr))
fprintf(stderr, "pthread: pthread_join() failed.\n");
else
printf("child returned %d.\n", *status_ptr);
printf("buffer='%s'\n", buffer);
return(0);
}