|
-
Dec 1st, 2006, 05:28 AM
#1
Thread Starter
Addicted Member
[RESOLVED] What is called thread safe?
-
Dec 1st, 2006, 06:36 PM
#2
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#.
-
Dec 2nd, 2006, 02:45 AM
#3
Thread Starter
Addicted Member
Re: What is called thread safe?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|