Date: Thu, 30 Jun 2005 01:06:36 -0400 From: Pablo Mora <fbsd.hackers@gmail.com> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: problem handling POSIX thread on FreeBSD Message-ID: <a9e342b50506292206204c80a2@mail.gmail.com> In-Reply-To: <200506290501.31301.jhb@FreeBSD.org> References: <a9e342b5050626200472f78ea5@mail.gmail.com> <200506271318.36748.jhb@FreeBSD.org> <a9e342b5050628165829056922@mail.gmail.com> <200506290501.31301.jhb@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
>Not sure I understand the question. What do you mean by S.O? =20 , sorry by my badly english, the correct word is O.S (operative system). >you saying that since the threads are POSIX, that you would >expect the program to act the same on all Operating Systems? exactly, that thought before your answer. I thought that a same code was executed of the same form so much in Solaris, in GNU/Linux and FreeBSD. At least than had shown the same results. really I do not know because Linux and solaris they show me: hilo1: puntero contiene 0 hilo2: puntero contiene 0 hilo1: puntero contiene 0 hilo2: puntero contiene 3 hilo1: puntero contiene 2 hilo2: puntero contiene 6 hilo1: puntero contiene 4 hilo2: puntero contiene 9 hilo1: puntero contiene 6 hilo2: puntero contiene 12 hilo1: puntero contiene 8 hilo2: puntero contiene 15 hilo1: puntero contiene 10 hilo2: puntero contiene 18 hilo1: puntero contiene 12 hilo2: puntero contiene 21 hilo1: puntero contiene 14 hilo2: puntero contiene 24 hilo1: puntero contiene 16 finaliza hilo1 con id 1082231728 hilo2: puntero contiene 27 finaliza hilo2 con id 1090624432 fin hilo 2 sadly in my university we work with Solaris:' ( ---------------------------------------------------------------------------= ----------------------- I repeat part of the code: /* file: test.c */ .... #include<pthread.h> char buffer[512]; pthread_mutex_t mutex, mutex2; pthread_t hilo1, hilo2; void f1(void* ptr) { int i,n=3D10; int valor=3D0; char*p=3D(char*)ptr; for(i=3D0;i<n;i++) { pthread_mutex_lock(&mutex); sscanf(p,"%d",&valor); printf("\thilo1: puntero contiene %d\n", valor); valor=3Di*3; sprintf(p, "%d",valor); pthread_mutex_unlock(&mutex2); } valor=3D(int)pthread_self(); printf("finaliza hilo1 con id %d\n", valor); pthread_exit(&valor); } void f2(void* ptr) { int i,n=3D10; int valor=3D0; char*p=3D(char*)ptr; for(i=3D0;i<n;i++) { pthread_mutex_lock(&mutex2); sscanf(p,"%d",&valor); printf("hilo2: puntero contiene %d\n", valor); valor=3Di*2; sprintf(p, "%d",valor); pthread_mutex_unlock(&mutex); } valor=3D(int)pthread_self(); printf("finaliza hilo2 con id %d\n", valor); pthread_exit(&valor); } int main() { pthread_attr_t atributos; =20 memset(buffer, '\0', sizeof(buffer)); =20 pthread_mutex_init(&mutex, NULL); //linux pthread_mutex_init(&mutex2, NULL); //linux pthread_mutex_lock(&mutex2); /* =BF? */ if(pthread_attr_init(&atributos) < 0) { perror("pthread_attr_init"); exit(-1); } if(pthread_attr_setscope(&atributos,PTHREAD_SCOPE_PROCESS) <= 0) { perror("pthread_attr_setscope"); exit(-2); } if(pthread_create (&hilo1, &atributos, (void*)&f1, (void*)buffer)<0) = =20 { perror("pthread_create hilo1"); exit(-2); } if(pthread_create(&hilo2, &atributos, (void*)&f2, (void*)buffer)<0) { perror("pthread_create hilo2"); exit(-2); } ..... } you believe that a mutex not necessarily must be unlocked by the same thread that locks it? sorry but my badly english, but I am making an effort to me so that you manage to understand to me. --=20 Concepci=F3n, Chile.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a9e342b50506292206204c80a2>