0

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!?

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by radu84
0

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"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.