Timão
unread,Jul 22, 2008, 2:35:51 PM7/22/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ccppbrasil
Galera,
O Código abaixo foi escrito por mim, apenas para título de exemplo,
como uso linux, compilei e ele rodou normalmente, mas quando fui
passar para windows deu a seguinte mensagem:
obs.: Estou usando dev-c++ com pthread-win32
Mensagem:
C:\teste>gcc definicoes.h main.c
C:\DOCUME~1\junior\CONFIG~1\Temp/ccukI6DX.o:main.c:(.text+0x4e):
undefined reference to `_imp__pthread_mutex_init'
C:\DOCUME~1\junior\CONFIG~1\Temp/ccukI6DX.o:main.c:(.text+0xba):
undefined refer ence to `_imp__pthread_create'
C:\DOCUME~1\junior\CONFIG~1\Temp/ccukI6DX.o:main.c:(.text+0x136):
undefined reference to `_imp__pthread_mutex_lock'
C:\DOCUME~1\junior\CONFIG~1\Temp/ccukI6DX.o:main.c:(.text+0x174):
undefined reference to `_imp__pthread_mutex_unlock'
collect2: ld returned 1 exit status
C:\teste>
Código:(O código funciona perfeitamente no linux)
//file: main.c
/*Criado por: Júnior e Lucas
Criado em: 27/06/08
Objetivo: Fazer um programa paralelo que some os dados de um vetor.
Trabalhar com Threads e com Buffer compartilhado.
*/
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include "definicoes.h"
thread_arg arguments[NUMERO_THREADS];
pthread_t Threads[NUMERO_THREADS];
pthread_mutex_t buffer_mutex;
int indice_global;
int vetor[1000];
int travado[1000];
float resultado;
void *Thread_Insere(void *thread);
int retorna_posicao_destravada();
int main(int argc, char *argv[]){
int i, opcao, verificador;
resultado = 0.0;
indice_global = 0;
pthread_mutex_init(&buffer_mutex, NULL);
/* ------------------------------------------- Leitura do arquivo do
vetor --------------------------------------- */
for (i = 0;i < 1000; i++){
vetor[i] = i;
travado[i] = 0;//0 destravado e 1 travado.
}
/* ----------------------------------------- Inserção na árvore
---------------------------------------------- */
for(i=0; i<NUMERO_THREADS; i++)
pthread_create(&(Threads[i]),NULL,Thread_Insere,NULL);
printf("\nResultado:%f",resultado);
}
int retorna_posicao_destravada(){
int i;
for(i = 0; i< 1000; i++)
if(travado[i] == 0)
return 1;
return 0;
};
void *Thread_Insere(void *thread){
//ptr_thread_arg argument = (ptr_thread_arg)thread;
while(retorna_posicao_destravada() == 1){
//lock
pthread_mutex_lock(&buffer_mutex);
resultado += vetor[indice_global];
travado[indice_global] = 1;
indice_global += 1;
pthread_mutex_unlock(&buffer_mutex);
//unlock
}
}
//end of main.c
//file:definicoes.h
#include<stdlib.h>
#include<stdio.h>
#define m 2
#define mm (m * 2)
#define FALSE 0
#define TRUE 1
#define NUMERO_THREADS 5
#define MAX_VETOR 30
typedef long TipoChave;
typedef struct Registro {
TipoChave Chave;
/*outros componentes*/
} Registro;
typedef struct Pagina* Apontador;
typedef struct Pagina {
short n;
Registro r[mm];
Apontador p[mm + 1];
int identificador;
} Pagina;
typedef struct {
int vezes_que_executa;
}thread_arg, *ptr_thread_arg;
void *Testa_Thread(void *threads);
void pausa();
int gera_vetor(int maximo);
int conta_vetor(char *nome_arquivo, int *tamanho);
int le_vetor(int *vetor, int tamanho_vetor, char *nome_arquivo);
//end of definicoes.h
Desde já agradeço.