FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Fork and mutual exclusion

 


umeshtangnu
Here's the problem:
I need to make a program in C that will create 5 threads using fork . Then, every thread will increase a global variable.

Now, only one thread can increase it at a specific time. So a mutual exclusion system has to be implemented.

Now : how do i go about creating that global counter that will be increased ?
I tried using a global variable and then access it's address through a pointer, but within every fork body, i get a different address

Any help .... please ?
snicker
The problem is that fork does not create a thread, but a process. The parent and child processes do not share their variables. They can, however, communicate using other mechanisms such as pipes.

You can discover something more from man 2 pipe on the command line, or on the really good book Advanced Linux Programming, freely downloadable from http://www.advancedlinuxprogramming.com

Hope this will help you.
Reply to topic    Frihost Forum Index -> Computers -> Software

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.