NetTalk Central

Author Topic: Using String Theory in a source (not a NetWebSource) procedure in NTWS  (Read 2766 times)

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Hi,

I intend to use ST in NTWS in a source (not a NetWebSource).
I want to use the split method but the result here will be a Queue in the st-object.
If I promise that the st object is only to be used in the souce procedure, my question is: Will this be safe or can instances of this same procedure in other threads corrupt the data in the st.lines queue?

Hope this question makes sense

Rene
Rene Simons
NT14.14

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
it's a good question Rene, and a common misunderstanding about what "thread safety" means.

The short answer is that _any_ local variable is completely and utterly thread safe. That includes objects (like StringTheory) and local queues.

The slightly longer answer is "except for variables that "point" to something global, and unthreaded". But that's not the normal use-case for local things so can (mostly) be ignored. (*)

Because locally declared queues (even the ones in StringTheory) are local, they are completely thread safe. So you can use it pretty much anyway you like. Indeed your source procedure is "re-entrant" meaning that because it's all local multiple threads can be running the same procedure, at the same time, and everything would still be ok. Indeed the procedure can even call itself and it would be ok.

(*) Queues can still be used in a global un-threaded way, but they need a bit of work to make them "safe". For example the Session Data Queue is a global, unthreaded queue that you access very happily using the GetSessionValue and SetSessionValue methods. Those methods contain the magic to make it thread safe.

(**) The key reason Queues are useless in WebServer projects, as say sources for a browse, is because global queues are "unsafe" (meaning that I don't trust you folks to use them properly) and local queues are too short-lived (meaning that the contents will disappear too quickly).

Cheers
Bruce



Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Very clear. Thank you.
Rene Simons
NT14.14