- 论坛徽章:
- 0
|
本帖最后由 zhuizhuziwo 于 2010-12-04 14:15 编辑
what a fucking day.there is no chinese in this system.so i use english. sorry.
I have written a program with two threads. but it has some errors.
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <string.h>
- #include <semaphore.h>
- #define MAX_LINE_LEN 256
- //the second thread.
- void * FirstThread(void *arg)
- {
- printf("Thread: %s\n", (char *)arg);
- //return EXIT_SUCCESS;
- return EXIT_FAILURE;
- //exit(EXIT_SUCCESS); //if this thread end with this ,there is no problem.
- }
- //main thread.
- int main()
- {
- pthread_t ptd;
- int rst;
- char str[MAX_LINE_LEN];
- printf("Input string<short<255>:");
- scanf("%s", str);
- rst = pthread_create(&ptd, NULL, FirstThread, (void *)str);
- if(rst != 0)
- {
- //perror("create thread error int %s, %d",__FILE__, __LINE__);
- exit (EXIT_FAILURE);
- }
- void *p_thrdRst;
- rst = pthread_join(ptd, &p_thrdRst);
- if(rst != 0) //last time i forgot this line.
- {
- perror("Error join.\n");
- exit (EXIT_FAILURE);
- }
- printf("Exit success\n");
- printf("Return string:%s\n", (char *)p_thrdRst);
- return EXIT_SUCCESS;
- }
复制代码 the print out has an addtional string: ": Success", i dont know why?
i run it like this.
Input string<short<255>:whdllo
Thread: whdllo
Error join.
: Success //Why??? it seems the perror calls print this message. |
|