1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

DLL static data

Discussion in 'C' started by rag84dec, Nov 30, 2008.

  1. rag84dec

    rag84dec New Member

    Joined:
    Jul 17, 2007
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,
    I have static data members in the class
    I have written to form static libraries.These static libraries are
    used to form a Dynamic link library.
    Do i need to use SEMAPHORE wile using those static data??
    Can you please help me in understanding this with an
    example?...Do i need to use semaphore at any other place??

    Thanks
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    You don't need any kind of mutexing arrangement just to access static data.
    If you want to update any kind of data (not just static) in a multithreaded program then you need to serialise access so that different threads do not clash, e.g.:
    thread 1: read memory, get value 1
    thread 2: read memory, get value 1
    thread 1: increase value and write back, storing 2
    thread 2: increase value and write back, storing 2

    Here we see that two threads have updated the same number, and the result should be 3.
     

Share This Page