Results 1 to 3 of 3

Thread: [RESOLVED] What is called thread safe?

  1. #1

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Resolved [RESOLVED] What is called thread safe?

    Thread safe means what?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: What is called thread safe?

    A thread-safe operation is one whose result will be the same every time it is performed, even if multiple threads are running at the same time. When you compile your high-level code (VB, C#, etc.) each line you write will be broken up into multiple instructions. When you're running multiple threads there is no guarantee that all the instructions that correspond to a single line of high-level code will be executed together. It's possible that the operation you intended to perform will be half-completed, then another thread start executing that changes the data that was being used. Then, when the first operation starts executing again it will not be using the same data it was, thus the result is indeterminate and may be different each time you run it.

    To make an operation thread-safe you must make sure that it completes in its entirety before any other thread can access the data it uses. This is called thread synchronisation and the .NET Framework has various tools available to help you do it. The simplest is the SyncLock statement in VB and the equivalent 'lock' statement in C#.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Re: What is called thread safe?

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width