21 lines
796 B
C
21 lines
796 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <pthread.h>
|
|
#include <string.h>
|
|
|
|
void* create_message(void* args) {
|
|
char* message = (char*)args;
|
|
char additional_message[50] = " This is a message from the thread. You've Created a thread!"; // Example additional message
|
|
strcat(message, additional_message); // Concatenate the additional message to the original message
|
|
printf("Hello from the thread! Message: %s\n", message);
|
|
return NULL;
|
|
}
|
|
|
|
int main() {
|
|
pthread_t t1;
|
|
char message[100] = "Welcome to Huajishe!"; // Original message to be passed to the thread
|
|
pthread_create(&t1, NULL, create_message, (void*)message);
|
|
pthread_join(t1, NULL);
|
|
printf("Message in main thread: %s\n", message); // Print the modified message in the main thread
|
|
return 0;
|
|
} |