Hi all now, for testing modified codes, i encounter a problem. please consider the following code:

procedure MyThreadNum5(Data: Pointer)  var   i:integer;  begin  1  lockvar.BeginRead;  2   try  3    i:=NumOfRxData;  4  finally  5     lockvar.EndRead;  6  end;    ....    end;

the above thread freezes on line #1; while in the main vcl thread of application, the codes between beginRead/endRead and beginWrite/ endWrite are executed. i have 7 occurrences of NumOfRxData global variable in units of Delphi2006 project. all of them, are protected by closed beginRead/endRead and beginWrite/ endWrite commands. All of global variables , are defined in the main (first) unit form of application.

Unit MainUnit;  ....    var    FormMainUnit: TFormMainUnit;    LockVar:TMultiReadExclusiveWriteSynchronizer;   ... (all global variables of application)    implementation    ...    initialization    RegisterClass(TFormMainUnit);    LockVar:=TMultiReadExclusiveWriteSynchronizer.Create;    finalization    FreeAndNil (LockVar);    end.

What is problem!?

i'm not sure about this line:
FreeAndNil (LockVar);

try to follow your code using watch and see what is happening there
also delphi's help says:"BeginRead does not return until there are no other threads writing to the memoryv"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.