Announcement

Collapse
No announcement yet.

THREADED numeric scalar variable expected

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

  • Michael Mattias
    replied
    >never use a thread variable in a loop, will be the question.

    regardless of what compiler restrictions may or may not exist....

    ...i think it would be safe to say there is no reason ever to use anything except a local for a for..next loop counter....

    .. but i can think of lots of uses for a threaded variable [u]within[/i] a loop.

    for example, here...

    terminate worker threads using windows events and using thread local storage demo dec 23 2005
    .. which i believe shows exactly using a local for a loop counter and threaded variables within the loop.

    ok, so that demo uses thread local storage; but you could use threaded variables as direct replacements for the counters and times i am storing in tls.

    which gives me an idea.... why doesn't some ambitious person take that demo, convert the tls to threaded variables, and post it as a 'reply'. sure sounds like an extra example of threaded variable usage in the source code forum would not be a bad thing!!!

    mcm


    Leave a comment:


  • Mike Doty
    replied
    Ooops, wrong forum.
    Will bring this subject up again, though.
    Never use a thread variable in a loop, will be the question.
    Thanks, Michael.
    THREAD CLOSED ......

    ------------------

    Leave a comment:


  • Michael Mattias
    replied
    'THREADED variables in FOR NEXT?

    Wrong forum. No such thing as THREADED in PB-DOS.

    That said, using a THREADED variable as a FOR..NEXT counter is, well, "strange."

    Using a THREADED variable in any program with no additional threads of execution is, well, "stange-er."

    Using a THREADED variable to pass information between functions may well be "strange-est."

    THREADED variables are the equivalent of Thread Local Storage. They are used when you need variables which are, for lack of a better term, "a GLOBAL for each current thread of execution.".. That is, the THREADED variable is visible by name to all functions within the current code module, but its value is maintained on a per-thread basis, so that any functions called from any thread context will be seeing the same variable.

    Any THREADED variable is kind of like an array with a hidden dimension of "current thread."

    Leave a comment:


  • Mike Doty
    started a topic THREADED numeric scalar variable expected

    THREADED numeric scalar variable expected

    'THREADED variables in FOR NEXT?
    Code:
    #DIM ALL
    #DIM ALL
    #COMPILE EXE
      THREADED t AS LONG
    '
      FUNCTION PBMAIN AS LONG
        t = 0                      'valid
        DO UNTIL t = 1             'valid
          INCR t                   'valid  
          MSGBOX STR$(t)
        LOOP
    '
        FOR t = 1 TO 1   'invalid numeric scalar variable expected
        NEXT
    END FUNCTION
    '
    'Should THREADED variables be used primarily for
    'passing values between functions and use REGISTER
    'variables for performance. Does the same thing
    'apply to GLOBAL integers and longs. Use REGISTER
    'variables for performance and then assign the result
    'to a THREADED or GLOBAL variable only when needed?

    ------------------


    [This message has been edited by Mike Doty (edited September 03, 2006).]
Working...
X