Date: Sat, 4 Jun 2005 16:19:39 -0400 From: Aziz Kezzou <french.linuxian@gmail.com> To: ray@redshift.com Cc: freebsd-hackers <freebsd-hackers@freebsd.org> Subject: Re: Fork mystries.... Message-ID: <3727392705060413194e5acda2@mail.gmail.com> In-Reply-To: <3.0.1.32.20050603174714.00a44990@pop.redshift.com> References: <3727392705060316555071c4ad@mail.gmail.com> <3.0.1.32.20050603174714.00a44990@pop.redshift.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Thank you guys, I got it fork is creating a different process. Currently, I am working a lot that I forget even the basic principales ;-)= =20 I need a break ... -aziz On 6/3/05, ray@redshift.com <ray@redshift.com> wrote: > Aziz, >=20 > Fork is for process creation. Look up pthread_create() and/or POSIX > thread > creation, etc. You should be able to find a lot of info on google with a > quick > search: =20 >=20 > http://math.arizona.edu/~swig/documentation/pthreads/ >=20 > From the OS standpoint a process is like a different program when you f= ork > it. > A thread is more like a single program with a bunch of subsections all > running > at the same time, then the OS and CPU jump back and forth giving a little > run-time to each subsection. Threads share a common space; processes [as > far as > I recal] do not (which is where inter process communication comes into > play). >=20 > Anyway, have fun! :) >=20 > Ray >=20 >=20 > At 07:55 PM 6/3/2005 -0400, Aziz Kezzou wrote: > | Hi all, > | It's probably not the right mailing list to ask but I am really > | surprised about global variable sharing in a multithreaded C > | application. If I remember well my multithreading course global > | variables are shared between threads, right ? > | =20 > | Example : > | ---------------------------- > | int counter =3D 0; > | int main() { > | if( fork()=3D=3D0) { > | while(1) { > | sleep(1); > | counter++; > | printf("Son : counter =3D %d\n", counter); =20 > | } =20 > | } else { > | while(1) { > | sleep(1); > | printf("Parent : counter =3D %d\n", counter); =20 > | } > | }=09=20 > | return 0; > | } > | ---------------------------- > |=20 > | All I get is : > | Parent : counter =3D 0 > | Son : counter =3D 1 > | Son : counter =3D 2 > | Parent : counter =3D 0 > | Son : counter =3D 3 > | Parent : counter =3D 0 > | Son : counter =3D 4 > | Parent : counter =3D 0 > |=20 > | why counter isn't shared between the two threads ??! > | thanks, > | -aziz > | _______________________________________________ > | freebsd-hackers@freebsd.org mailing list > | http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > | To unsubscribe, send any mail to > "freebsd-hackers-unsubscribe@freebsd.org" > |=20 > |=20 >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3727392705060413194e5acda2>