Regarding reentrant code.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rit
    New Member
    • Apr 2007
    • 1

    Regarding reentrant code.

    Hi,

    I wrote the following code and ran the executable from two different unix terminals( to the same server).
    static int p=7;
    main()
    {
    cout << " addrs is "<<&p;//display the address of p
    while(1)
    {if(getchar())
    p++;
    cout<<" p is "<<p;
    }

    }

    Now these 2 executables( processes) are executing the same program. On a unix system the location of variable p should be different for both the processes. however i saw that the output for both the processes displayed the same address.Also if the address is indeed same then these two processes should have interfered with each other's copy of "p", but that didn't happen either. both were executing independently of each other. Please help in understanding this.

    Thanks,
    Ritesh.
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    the address you get is the address of the variable within the process virtual address space. The memory management unit maps references to the virtual address to the actual physical address used to store the variable. Have a read thru
    http://en.wikipedia.or g/wiki/Memory_manageme nt_unit

    Comment

    Working...