FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
Love is Love
•What the mean of Globalization
can we fork
Mutual funds during Market fall...
Hurting yourself on accident
How safe is the Stock Market
How to prepare a "robots.txt" to get crawled by Se
Possibly going to fork some code
Pakistan, Turkey agree for Mutual Corporation
3 Jokes
20 Frih$
mIRC for begginers.
Dose Anybody Know Where to find Photoshop pro Free Software.
Island Natives!!
Reply to topic    Frihost Forum Index -> Computers -> Software

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