Ask a questionAsk a question
 

AnswerTwo threads, One Method

  • Friday, November 06, 2009 10:20 AMBramenator Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Guys.

    I'm working in VS 2008 C#  and C# CF
    I have a method with a String parameter and returning an encoded string.
    If I have two threads which call this method, and at some point they call the method at the same time with two different parameters. Will this infuence the returned result of the method to each thread individually, or will I have to do something else to synchronize/join the threads?

    Thank you....

Answers

  • Monday, November 09, 2009 9:59 AMMorantex Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Guys.

    I'm working in VS 2008 C#  and C# CF
    I have a method with a String parameter and returning an encoded string.
    If I have two threads which call this method, and at some point they call the method at the same time with two different parameters. Will this infuence the returned result of the method to each thread individually, or will I have to do something else to synchronize/join the threads?

    Thank you....

    A method that can be active by two or more execution threads at once, is called "reentrant" and is entirely valid and normal in computing.

    In order to work reliably in such a way that no executiin thread impacts any other, some rules must be followed, see this article.

    If your code simply manipulates a supplied argument and uses only local (stack) variables in doing so, then it will be fine.

    You only need to worry of any of the data accessed (directly or indirectly) by the code is shared or shreable, if not, then all is well.

    Does that help?

    Hugh




    Hugh Moran - http://www.morantex.com
    • Marked As Answer byBramenator Tuesday, November 10, 2009 5:37 AM
    •  

All Replies

  • Monday, November 09, 2009 9:59 AMMorantex Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Guys.

    I'm working in VS 2008 C#  and C# CF
    I have a method with a String parameter and returning an encoded string.
    If I have two threads which call this method, and at some point they call the method at the same time with two different parameters. Will this infuence the returned result of the method to each thread individually, or will I have to do something else to synchronize/join the threads?

    Thank you....

    A method that can be active by two or more execution threads at once, is called "reentrant" and is entirely valid and normal in computing.

    In order to work reliably in such a way that no executiin thread impacts any other, some rules must be followed, see this article.

    If your code simply manipulates a supplied argument and uses only local (stack) variables in doing so, then it will be fine.

    You only need to worry of any of the data accessed (directly or indirectly) by the code is shared or shreable, if not, then all is well.

    Does that help?

    Hugh




    Hugh Moran - http://www.morantex.com
    • Marked As Answer byBramenator Tuesday, November 10, 2009 5:37 AM
    •