Q1)このファイル名を、main.cppに変更して、コンパイルが出来る方法はありますか?
pthread_create(&thid, NULL, thread, "thread1") がエラーになります。
Q2)strcpy(ret, "This is a test")の警告をなくする方法はありますか?
//ファイル:main.c===================
#define _OPEN_THREADS
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
void *thread(void arg) {
char ret;
printf("thread() entered with argument '%s'\r", (char)arg);
if ((ret = (char) malloc(20)) == NULL) {
perror("malloc() error");
exit(2);
}
strcpy(ret, "This is a test");
//警告: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]
pthread_exit(ret);
}
int main() {
pthread_t thid;
void *ret;
if (pthread_create(&thid, NULL, thread, "thread1") != 0) { //ここでmain.cppではエラ−になります。
perror("pthread_create() error");
exit(1);
}
if (pthread_join(thid, &ret) != 0) {
perror("pthread_create() error");
exit(3);
}
printf("**thread exited with '%s'¥r", (char)ret);
return 0;
}
以上、宜しくお願いします。
補足)
pthread_createの使用が間違いであり、他の命令を使用すべきでしょうか?
尚、このスレッドの中で、Windowsで言うところのWaitForSingleObject()を
使用して、イベント待ちをしたいと考えています。
回答1件
あなたの回答
tips
プレビュー