Allows a thread to write to the protected memory when it is safe to do so.
function BeginWrite: Boolean;
__fastcall Boolean BeginWrite();
BeginWrite obtains an exclusive write lock on the memory protected by the synchronizer object. Call BeginWrite before writing to this memory. BeginWrite does not return until no other threads are reading from or writing to the memory. After a thread calls BeginWrite, any other thread asking to access that memory by calling BeginRead or BeginWrite must wait until the writing thread calls EndWrite.
Note that a write lock operation is not atomic. Data in protected memory will always be in a consistent state when BeginWrite returns, but is not necessarily in the same state as when BeginWrite was called. As a rule, a thread should always discard previous samples from protected memory after promoting a read lock to a write lock. However, the calling thread can determine whether a state change has occurred by examining return value of BeginWrite: true if protected memory has not be written to by another thread, false if another thread may have modified protected memory.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!