0

I have an async function that calls an sync function they are both static if it matters. My sync function consists private variables in it. Theoretically is there any chance that there will be variables collision in the sync function?

For example: Async calls the sync function twice exactly in the same time. Will the sync functions use the same private variables memory allocation or each one will allocate memory for the variables and when it finishes it will free them from the memory.

Thank you.

Ron Peleg
  • 11
  • 1
  • 1
    I am not sure i am correctly in sync with your terminology of async and sync. Are you using threads? Tasks? Async/await? Also, the variables tjat you are calling private, are private-to-function or private-to-class? You said things are static. So there could be risk. Show some code if you can – inquisitive Feb 17 '17 at 06:52
  • See also https://stackoverflow.com/questions/3473615/does-a-static-method-share-its-local-variables-what-happens-during-concurrent. It is not entirely clear to me what you mean by "private variables" here, but it seems like you're talking about local variables declared within a method body. If so, the marked duplicate and other link directly address your question. If not, then please fix your question so that it's clear what you mean. Make sure you provide a good [mcve] that completely and succinctly illustrates what it is you're asking about. – Peter Duniho Feb 17 '17 at 07:26
  • Note that with respect to local variables, it doesn't matter in what context the method is called. Asynchronous/threaded, synchronous, it doesn't matter. You still get a whole new instance of the variable, independent of any other instance, each time the method is called. – Peter Duniho Feb 17 '17 at 07:27

0 Answers0