Jump to content

David Heffernan

Members
  • Content Count

    3711
  • Joined

  • Last visited

  • Days Won

    185

Posts posted by David Heffernan


  1. Works fine in any context. If you notice though, I supplied a complete program. You only supplied snippets, the latest of which does not compile. Perhaps if you want help finding the bug in your code you could supply a complete but minimal reproduction, just as I did. Then it would be simple for us to find the mistake. 


  2. Works fine here.  I wrote a version with the threading removed to make it simpler to understand.

     

    {$APPTYPE CONSOLE}
    
    uses
      System.SysUtils;
    
    function CaptureValue(Value: Integer): TProc;
    begin
      Result :=
        procedure
        begin
          Writeln(Value);
        end;
    end;
    
    procedure Main;
    var
      i, j: Integer;
      Procs: TArray<TProc>;
    begin
      SetLength(Procs, 10);
    
      for i := 0 to 9 do
        Procs[i] :=
          procedure
          begin
            Writeln(i);
          end;
      for j := 0 to 9 do
        Procs[j]();
    
    
      for i := 0 to 9 do
        Procs[i] := CaptureValue(i);
      for j := 0 to 9 do
        Procs[j]();
    end;
    
    begin
      Main;
      Readln;
    end.

    Output is

    10
    10
    10
    10
    10
    10
    10
    10
    10
    10
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9

     


  3. 58 minutes ago, OmahaMax said:

    Yes, it is a simple TStringList. However, when the output is posted in the final inserter stage, the inserted output matches the stringlist results. One thread works, two threads fail to process the first input, three threads fail to process the first two inputs, and so forth. Results are the same with or without logging.

    Would be easier for people to help if you could post a minimal repro. 


  4. 1 hour ago, Steve Maughan said:

    Hi Stefan,

     

    Each item's value changes slightly on each iteration. Note also, finding the min item may take more than one comparison per change (if the min item's value changes such that it's not now the min item).

     

    Thanks,

     

    Steve

    On each iteration, each value is modified. So, during the iteration, just keep track of the smallest value that you have seen to date. 


  5. 1 hour ago, Lars Fosdal said:

    Depends on the dictionary, I guess.

    Race conditions rarely flag as errors, but cause inconsistent or erratic data, possibly leading to wrongful processing later on.

    In this case, at least one of the four parties would be denied access (due to exclusive write lock and - depending on the programmmer - exclusive read) to the file and hence should have/raise awareness of a problem. 

    But, whatever.

    Well, there are plenty of types for which races lead to errors. But how races manifest is not part of what defines them. A race is simply unserialised access to a shared resource. There aren't multiple definitions of this term. 


  6. 34 minutes ago, Dmitry Arefiev said:

    We have two problems:

    1) REST, DBX, System.JSON duplicating JSON serialization classes.

    2) Non complete docu for (1) classes.

     

    We want to keep only System.JSON with options for backward compatibility with REST, DBX. And only to develop System.JSON. When this will happen, then all demos, tests (internal), docu, must be updated to reflect the current RTL state. Now it is not the time for docu work ...

    I don't buy that argument.  People are using the software now.  And software is never finished.  There is always more to be done.  So if you wait until it is done, then you never document it.

     

    My personal experience, and very strongly felt, is that writing documentation is a key part of finalising and debugging specification.  So many times have I experienced this.  Only when you write the documentation do you realise some of the issues that users will face.  Deal with them before releasing and you don't have to spend as much time in back compat hell.

     

    My view is that writing documentation in a timely fashion actually saves time and resources in the long run.

    • Like 5

  7. 9 hours ago, Jacek Laskowski said:

    The question was simple:
    does RTL have functions to convert a string to JSON?

    There are two answers:
    1. Yes, it's FunctionX function from ModuleY module
    2. No, there is no such function

    And I asked because I did not find it, and I do not like to reinvent a wheel.

    Why did you decide that 2 is the answer? 


  8. 6 hours ago, David Heffernan said:

    I'd read that as "GetMemory exists so that the Crtl unit can implement malloc". 

    But actually, that turns out to be completely wrong.  At least in XE7 malloc is implemented as

     

    function  malloc(size: size_t): Pointer; cdecl;
    begin
      Result := AllocMem(size);
    end;

     

    which is pretty lame because AllocMem is zeroising the memory. And potentially throwing an exception. So, a somewhat bogus attempt to implement malloc. 

     

    Perhaps what is really going on is that GetMemory is the function that you need to call if you want to allow GetMemory(0) to return a pointer to a block of memory, ie. that GetMemory(0) <> nil.  But I'm not convinced by that either since the C standard demands that malloc(0) returns a value that cannot be dereferenced, which may or may not be null.

     

    Or perhaps it is just a function that returns nil in case of error rather than raising an exception.

×