資源簡介
設有二元函數 f(x,y) = f(x) + f(y)
其中: f(x) = f(x-1) * x (x >1)
f(x)=1 (x=1)
f(y) = f(y-1) + f(y-2) (y> 2)
f(y)=1 (y=1,2)
請編程建立 3 個并發協作進程或線程,它們分別完成 f(x,y)、f(x)、f(y)
代碼片段和文件信息
#include
#include
#include
#include
void?fx(int?*);
void?fy(int?*);
void?fxy(int?*);
int??fxx(int?x);
int??fyy(int?y);
int?rxry;
pthread_t?thrdxthrdythrdxy;
int?pipex[2]pipey[2];
int?main(int?argcchar?*arg[]){
int?ret;
int?xy;
printf(“Please?enter?x\n“);
scanf(“%d“&x);
printf(“Please?enter?y\n“);
scanf(“%d“&y);
printf(“x=%d\n“x);
printf(“y=%d\n“y);
if(pipe(pipex)<0){
perror(“pipex?not?creat“);
exit(EXIT_FAILURE);
}
if(pipe(pipey)<0){
perror(“pipe?not?creat“);
exit(EXIT_FAILURE);
}
ret=pthread_create(&thrdxNULL(void?*)fx(void?*)&x);
if(ret){
perror(“pthread_create:fx“);
exit(EXIT_FAILURE);
}
ret=pthread_create(&thrdyNULL(void*)fy(void*)&y);
if(ret){
perror(“pthread_create:fx“);
}
ret=pthread_create(&thrdxyNULL(void*)fxy(void*)&x);
i
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?-rw-rw-r--????????34??2010-05-22?15:15??exp2\緙栬瘧璇存槑
?-rw-rw-r--??????1429??2010-04-14?19:29??exp2\exp2.c
?-rwxr-xr-x?????10118??2010-05-22?15:15??exp2\exp2
?drwxrwxr-x?????????0??2010-05-25?12:02??exp2
-----------?---------??----------?-----??----
????????????????11581????????????????????4
- 上一篇:從TS文件中搜索獲得節目信息
- 下一篇:實驗十、分布式系統實驗
評論
共有 條評論