Re: problem handling POSIX thread on FreeBSD

2005-06-29 Thread Pablo Mora
Not sure I understand the question.  What do you mean by S.O?  

, 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 */

#includepthread.h

char buffer[512];
pthread_mutex_t mutex, mutex2;
pthread_t hilo1, hilo2;

void f1(void* ptr)
{
   int i,n=10;
   int valor=0;
   char*p=(char*)ptr;

   for(i=0;in;i++)
   {
   pthread_mutex_lock(mutex);
   sscanf(p,%d,valor);
   printf(\thilo1: puntero contiene %d\n, valor);
   valor=i*3;
   sprintf(p, %d,valor);

   pthread_mutex_unlock(mutex2);
   }
   valor=(int)pthread_self();
   printf(finaliza hilo1 con id %d\n, valor);
   pthread_exit(valor);
}
void f2(void* ptr)
{
   int i,n=10;
   int valor=0;
   char*p=(char*)ptr;
   for(i=0;in;i++)
   {
   pthread_mutex_lock(mutex2);
   sscanf(p,%d,valor);
   printf(hilo2: puntero contiene %d\n, valor);
   valor=i*2;

   sprintf(p, %d,valor);
   pthread_mutex_unlock(mutex);
   }
   valor=(int)pthread_self();
   printf(finaliza hilo2 con id %d\n, valor);
   pthread_exit(valor);
}


int main()
{
   pthread_attr_t atributos;

   memset(buffer, '\0', sizeof(buffer));
   
   pthread_mutex_init(mutex, NULL); //linux
   pthread_mutex_init(mutex2, NULL); //linux

   pthread_mutex_lock(mutex2);  /* ¿? */

   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)  
   {
 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.

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem handling POSIX thread on FreeBSD

2005-06-28 Thread Pablo Mora
Ok, I understand, but by being threads POSIX should be executed of the
same one in any type of S.OR?

thanks to all
-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem handling POSIX thread on FreeBSD

2005-06-28 Thread Pablo Mora
S.O , sorry

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


problem handling POSIX thread on FreeBSD

2005-06-26 Thread Pablo Mora
/* file: taller.c */

int main() {

if(pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0)
 /* handler */


}

$ gcc taller.c -pthread
$ ./a.out
pthread_attr_setscope: Unknown error: 0
$

PTHREAD_SCOPE_SYSTEM fail on freebsd ?

help me please... 

very thanks...

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem handling POSIX thread on FreeBSD

2005-06-26 Thread Pablo Mora
Hi, very thanks you... i running fbsd v4.11 stable.

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: problem handling POSIX thread on FreeBSD

2005-06-26 Thread Pablo Mora
/* file: test.c */
#includestdio.h
#includepthread.h
#includestring.h
#includeunistd.h
#includestdlib.h

char buffer[512];
pthread_mutex_t mutex, mutex2; 
pthread_t hilo1, hilo2;

void f1(void* ptr)
{
int i,n=10;
int valor=0;
char*p=(char*)ptr;

for(i=0;in;i++)
{
pthread_mutex_lock(mutex);
sscanf(p,%d,valor);
printf(\thilo1: puntero contiene %d\n, valor);
valor=i*3;
sprintf(p, %d,valor);

pthread_mutex_unlock(mutex2);
}
valor=(int)pthread_self();
printf(finaliza hilo1 con id %d\n, valor);
pthread_exit(valor);
}
void f2(void* ptr)
{
int i,n=10;
int valor=0;
char*p=(char*)ptr;
for(i=0;in;i++)
{
pthread_mutex_lock(mutex2);
sscanf(p,%d,valor);
printf(hilo2: puntero contiene %d\n, valor);
valor=i*2;

sprintf(p, %d,valor);
pthread_mutex_unlock(mutex);
}
valor=(int)pthread_self();
printf(finaliza hilo2 con id %d\n, valor);
pthread_exit(valor);
}

int main()
{
pthread_attr_t atributos;
//pthread_mutexattr_t mutexattr; - solaris

memset(buffer, '\0', sizeof(buffer));
/*
   
if(pthread_mutexattr_setpshared(mutexattr,PTHREAD_PROCESS_PRIVATE)!=0)
//solaris
{
perror(pthread_mutexattr_setpshared);
exit(-12);
}
*/

pthread_mutex_init(mutex, NULL); //linux
pthread_mutex_init(mutex2, NULL); //linux

pthread_mutex_lock(mutex2); /

/*if(pthread_mutex_init(mutex, mutexattr)!=0) //solaris
{
perror(pthread_mutex_init);
exit(-2);
}*/

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)
{
perror(pthread_create hilo1);
exit(-2);
}
if(pthread_create(hilo2, atributos, (void*)f2, (void*)buffer)0)
{
perror(pthread_create hilo2);
exit(-2);
}


if(pthread_join(hilo2, NULL)0)
{
perror(pthread_join hilo1 );
exit(-3);
}
puts(fin hilo 2);
/*if(pthread_join(hilo1, NULL)0)
{
perror(pthread_join hilo2 );
exit(-3);
}*/


pthread_mutex_destroy(mutex);
exit(0);
}

output in solaris and linux: (gcc test.c -lpthread)
  
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

output on FreeBSD v4.11 STABLE (gcc test.c -pthread):

hilo1: puntero contiene 0
hilo1: puntero contiene 0
hilo1: puntero contiene 3
hilo1: puntero contiene 6
hilo1: puntero contiene 9
hilo1: puntero contiene 12
hilo1: puntero contiene 15
hilo1: puntero contiene 18
hilo1: puntero contiene 21
hilo1: puntero contiene 24
finaliza hilo1 con id 134534144

why ??

help me please :-).

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


help me with C languaje please, re: files.

2005-06-04 Thread Pablo Mora
Hi all, 

I am programming in C and I need to read a quantity of lines of a
file.  How can I know when a line arrives at his end? exists some
special character?  exists some file in C in the kernel of FreeBSD
(4.11) where I can find somewhat similar?

example: how read four lines of a file. 

thanks and sorry for my badly English.
-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: help me with C languaje please, re: files.

2005-06-04 Thread Pablo Mora
#include stdio.h
#include stdlib.h

int main(void) {

 FILE *p_to_f;
 char buf[1024];
 int i, j = 0;

 p_to_f = fopen(test,r);

 if(p_to_f == NULL) {
  perror(fopen);
  exit(EXIT_FAILURE);
 }

 for(i = 0; i  4  !feof(p_to_f); i++) {
  fgets(buf,1024,p_to_f);
  printf(%s, buf);
 }

 fclose(p_to_f);

 return 0;

}

I expect that be well what I did.  Thanks Victor.

PD Corrigeme Si hay algo malo. :D

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Files in C.

2005-05-05 Thread Pablo Mora
Greg, i am going to keep in mind your words.  In fact I expect to
guide me for more than an opinion.  Hopefully they accept occasionally
some my code written in C so that they help me to perfect it and i
hope be not an inconvenience.

PD. Any objection with the previous thing tell it to me please.  

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Files in C.

2005-05-04 Thread Pablo Mora
what do they think of the book: Advanced Programming In The Unix
Environment (Richard Stevens) ??

is a good option to learn C on Unix ?

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Files in C.

2005-05-04 Thread Pablo Mora
thanks to all by responding me, I will have present each one of its mail

PD. I thank to the community of FreeBSD by facilitating me its aid.  

TnX from Chile.

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Files in C.

2005-05-03 Thread Pablo Mora
I know that this is not the place to consult on programming C.  But I
am so enthusiastic in FreeBSD that I want to learn more on the
language C and someday coming to be a small part of which you already
are.  It wanted that they recommended to me some webpage where to be
able to obtain information on files in C.  I want to learn well to
work with Files.

I need to know the best place where to obtain information and I know
that you know it.

Bye and very very thanks.

PD. thousand excuses by my terrible English.

they say that more idiot is the one than does not ask.
Dicen que más tonto es aquél que no pregunta.

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Files in C.

2005-05-03 Thread Pablo Mora
Thanks by responding me.  I will revise each direction that have given
me and truly I thank it a lot.

-- 
Concepción, Chile.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]