如何解决此警告 [英] How to fix this warning

查看:598
本文介绍了如何解决此警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!!!

我想创建一个程序,它接收一个数字N作为参数并启动N个线程,每个线程同步显示一个从1到N的数字(带有命名或匿名信号量)选择)产生有序序列(12 ... N)*。

这里是我的代码



hello!!!
I want to Create a program that receives a number N as an argument and starts N threads each displaying one of a number from 1 to N synchronously (with named or anonymous semaphores of choice) to produce an ordered sequence (12 ... N) *.
here is my code

int N;
void* f0(int k, sem_t *mutex) {
	
    for(int i = 0; i < 100; i++) {
    	if(k < N-1){
    		sem_wait(&mutex[k]);
    		//printf("value[] = %d", value[k]);
    		printf("%d\n",k+1);
    		k = k + 1;
    		sem_post(&mutex[k]);
    		//printf("i =%d \n",i);
    		

    	}
    	
    	else{
    		
    		sem_wait(&mutex[N-1]);
    		printf("%d\n",k+1);
    		k = N-k-1;
    		sem_post(&mutex[k]);
    		//printf("i =%d \n",i);
    		

    	}
    }
    
    return NULL;
}
int main(int argc, char *argv[]) {
	N = atoi(argv[1]);
	int *value;
	value= malloc(sizeof(int)*N);
	sem_t *mutex;
	mutex =malloc(sizeof(sem_t)*N);
	pthread_t pid[N];
	
	for (int i =0;i<N;i++){
		if(i==0){
			value[i]=1;
		}
		else{
			value[i]=0;
		}
	}
	for(int i=0;i<N;i++){
		sem_init(&mutex[i],0,value[i]);
	}
	int m =0;
	while(m<N){
        pthread_create(&pid[m], NULL, f0(m,&mutex),0);
        m=m+1;
        printf("m = %d\n", m );
        
	}
	printf("heyG\n");
	for (int i=0;i<N;i++){
		pthread_join(pid[i],0);
	}
	for (int i=0;i<N;i++){
		sem_destroy(&mutex[i]);
	}
	return EXIT_SUCCESS;
}





我的尝试:



我得到这个警告,我想解决它





What I have tried:

I get this warning and I want to fix it

copie.c: In function ‘main’:
copie.c:60:44: warning: passing argument 2 of ‘f0’ from incompatible pointer type [-Wincompatible-pointer-types]
         pthread_create(&pid[m], NULL, f0(m,&mutex),0);
                                            ^
copie.c:11:7: note: expected ‘sem_t * {aka union <anonymous> *}’ but argument is of type ‘sem_t ** {aka union <anonymous> **}’
 void* f0(int k, sem_t *mutex) {

推荐答案

尝试
pthread_create( &pid[m], NULL, f0, 0 );

当传递指向函数的指针时,参数是不包括在内。

When passing a pointer to a function the arguments are not included.


这篇关于如何解决此警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆