-
大小: 4KB文件類型: .rar金幣: 1下載: 0 次發(fā)布日期: 2021-01-09
- 語(yǔ)言: 其他
- 標(biāo)簽: 操作系統(tǒng)??實(shí)驗(yàn)二??
資源簡(jiǎn)介
設(shè)有二元函數(shù) 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)
請(qǐng)編程建立 3 個(gè)并發(fā)協(xié)作進(jìn)程或線程,它們分別完成 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
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?-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
評(píng)論
共有 條評(píng)論