[問題] 關於新手想於 VC6.0 使用 pthread
遇到的問題 : 小弟想於windows環境下(VC6.0) 使用pthread實作多執行序
小弟將書上寫的code key in並執行
結果發生error C2664: 'pthread_create' : cannot convert
parameter 3 from 'void *' to 'void *(__cdecl
*)(void *)' Conversion from 'void*'
to pointer to non-'void' requires an explicit cast
開發平台: VC++
有問題的code:
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
void do_one_thing(int *);
void do_another_thing(int *);
void do_wrap_up(int,int);
int r1=0,r2=0;
void main()
{
pthread_t thread_1,thread_2;
pthread_create(&thread_1 , NULL , (void *) do_one_thing , (void *) &r1);
pthread_create(&thread_2 , NULL , (void *) do_another_thing ,(void *) &r2);
// do_one_thing(&r1);
// do_another_thing(&r2);
pthread_join(thread_1,NULL);
pthread_join(thread_2,NULL);
do_wrap_up(r1,r2);
}
void do_one_thing(int *pnum_times)
{
int i,j,x;
for(i=0;i<4;i++)
{
printf("doing one thing\n");
for(j=0;j<100000;j++)
x=x+i;
(*pnum_times)++;
}
}
void do_another_thing(int *pnum_times)
{
int i,j,x;
for(i=0;i<4;i++)
{
printf("doing another\n");
for(j=0;j<10000;j++)
x=x+i;
(*pnum_times)++;
}
}
void do_wrap_up(int one_times,int another_times)
{
int total;
total = one_times+another_times;
printf("ALL done,one thing %d,another %d \nfor a total of %d\n",
one_times,another_times,total);
}
補充說明:小弟不才,若想於VC下使用pthread語法,是只要將.DLL,.lib,.h
分別加入至相對應路徑中就可以work嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.135.11.124
→
03/21 20:15, , 1F
03/21 20:15, 1F
→
03/22 05:14, , 2F
03/22 05:14, 2F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章