Announcement

Collapse
No announcement yet.

DLL Instances Threads etc.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DLL Instances Threads etc.

    I seem not to be able to get this right.
    This is the plot.
    Code:
    PROGRAM loads an RUNTIME DLL
       When loaded RUNTIME checks if PROGRAM has an valid INI-file
       If not PROGRAM will not start.
    PROGRAM Initialize RUNTIME with diverse GLOBAL assignments.
    PROGRAM calls a function in WORKER1 DLL
       WORKER1 starts a new Thread and returns to PROGRAM
       WORKER1 Thread calls functions in RUNTIME
    PROGRAM calls a function in  WORKER2 DLL
       WORKER2 starts a new Thread and returns to PROGRAM
       WORKER2 Thread calls functions in RUNTIME
    PROGRAM calls a function in  WORKER3 DLL
       WORKER3 starts a new Thread and returns to PROGRAM
       WORKER3 Thread calls functions in RUNTIME
       WORKER3 Thread calls a function in WORKER2 witch calls a function in RUNTIME 
    Etcetera...
    For the record...
       Globals in RUNTIME is static, ie they are not changed by
       WORKER(S)
    The Question:
       All this Globals as initialised by PROGRAM
       are they ALWAYS seen with their initialised value by any thread in WORKER DLL-s?
    Thanks for your help


    -------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited February 26, 2000).]
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

  • #2
    Also for the record:
    a GLOBAL in a DLL is LOCAL to the DLL, so I am not asking
    if a global in RUNTIME can be accessed from WORKER or another
    part of the code not belonging to RUNTIME


    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Comment


    • #3
      STATIC/GLOBAL variables in subs/functions are seen by all threads in the process that call them. In other words, if you have a sub in PROGRAM that alters any global/static variable and that sub is called from a thread, then the code is not threadsafe...

      When changing any variable that can be read and changed by other threads, you must use a CRITICALSECTION or some other synchronization technique to ensure that the data is not partially updated while being read by another thread during a context-switch.

      Michael Mattias wrote an article (recently in Basically Speaking magazine) on synchronization... it give you a basic idea, but does not really cover allocating and managing Thread Local Storage, or TLS as it is known. (Hint hint!)

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment

      Working...
      X