Ver Mensaje Individual
  #8  
Antiguo 11-06-2007
Avatar de mamcx
mamcx mamcx is offline
Moderador
 
Registrado: sep 2004
Ubicación: Medellín - Colombia
Posts: 3.911
Reputación: 25
mamcx Tiene un aura espectacularmamcx Tiene un aura espectacularmamcx Tiene un aura espectacular
Cita:
Empezado por jachguate
Hay otras cosas que no entiendo que hacen en el roadmap, pues son cosas que ya existen y para quienes no conocen el producto, esto da la idea de que no existiesen actualmente, cosas como
Quizas lo de RIIA un poco por medio de Intraweb (sera que apuntan a una solucion propia??).

Pero lo de multicore? Pa' que entiendas por donde *deberia* de ser la vuelta de la programacion multi-core un vistazo a:

http://erlang.org/doc/doc-5.5.4/doc/...art_frame.html

Y para una explicacion del porque el estilo actual no sirve (y el de erlang si ):

http://www.defmacro.org/ramblings/concurrency.html

Ese es el camino a tomar.


Hace un par de meses intente hacer una implemtacion de erlang concurrency en delphi pero no soy tan hacker y quede a 1/4 de camino

Código Delphi [-]
unit ParallelCode;

interface

uses
  {VCL}Classes ,
  {JCL}JclContainerIntf,JclQueues,JclAlgorithms,JclHashMaps;

type
  TBufferType = (tbInt,tbString,tbData);

  IParallelCode = interface
    function GetSession(key: String): TObject;
    procedure SetSession(key: String; const Value: TObject);

    procedure Post(PID:Integer;Value:String);

    procedure BroadCast(PidList: array of Integer;Value:String);overload;
    procedure BroadCast(Value:String);overload;
    procedure Execute;
    procedure Get(FromPID:Integer;Value:String);

    property Session[key:String]:TObject read GetSession write SetSession;

    function GetIsDone: Boolean;
    function GetPid: Integer;
  end;

  TParallelCode = class(TInterfacedObject,IParallelCode)
  private
    FPId : Integer;
    FSession: IJclStrIntfMap;
    FIsDone: Boolean;
    function GetIsDone: Boolean;
    function GetPid: Integer;
    function GetSession(key: String): TObject;
    procedure SetSession(key: String; const Value: TObject);
  protected
    FApply:TApplyFunction;
    FValue:TObject;

    procedure DoPost(PID:Integer;Value:TStream;DataType:TBufferType);virtual;
  public
    procedure Execute;

    procedure Post(PID:Integer;Value:String);

    procedure BroadCast(PidList: array of Integer;Value:String);overload;
    procedure BroadCast(Value:String);overload;

    procedure Get(FromPID:Integer;Value:String);

    property Session[key:String]:TObject read GetSession write SetSession;

    property IsDone:Boolean read GetIsDone;

    property PID:Integer read GetPid;

    constructor Create(Apply:TApplyFunction;Data:TObject;AutoStart:Boolean=True);
    destructor Destroy; override;

end;

implementation

{ TParallelCode }

procedure TParallelCode.BroadCast(PidList: array of Integer; Value: String);
var
  Pid:Integer;
begin
  for Pid in PidList do
  begin
    Post(Pid,Value);
  end;//for
end;

procedure TParallelCode.BroadCast(Value: String);
begin

end;

constructor TParallelCode.Create(Apply: TApplyFunction; Data: TObject;AutoStart:Boolean=True);
begin
  FSession := TJclStrIntfHashMap.Create();

  FApply := Apply;
  FValue := Data;

  if AutoStart then
  begin
    Execute;
  end;
end;

destructor TParallelCode.Destroy;
begin
  Post(-1,'Terminado');

  FSession.Clear;
  FApply := nil;
  FValue := nil;
  inherited;
end;

procedure TParallelCode.DoPost(PID: Integer; Value: TStream;
  DataType: TBufferType);
begin

end;

procedure TParallelCode.Execute;
var
  value:Integer;
begin
  Value := Integer(FApply(FValue));
end;

procedure TParallelCode.Get(FromPID: Integer; Value: String);
begin

end;

function TParallelCode.GetIsDone: Boolean;
begin

end;

function TParallelCode.GetPid: Integer;
begin

end;

function TParallelCode.GetSession(key: String): TObject;
begin
  Result := nil;
end;

procedure TParallelCode.SetSession(key: String; const Value: TObject);
begin

end;

procedure TParallelCode.Post(PID: Integer; Value: String);
var
  Bufer: TStringStream;
begin
  Bufer := TStringStream.Create(Value);

  DoPost(PID,Bufer,tbString);
end;

end.

Código Delphi [-]
unit FastCore2;

interface

uses {VCL} Windows, Classes, Messages ,
     {JCL}JclContainerIntf,JclQueues,JclAlgorithms,JclArrayLists, Coroutine;

type
  TPIdList = array of Integer;

  TForkManager= class(TObject)
  private
    FList: IJclIntfArray;
  public

  end;

  TForkMethod = class(TCoroutine)
  end;

  TFork = class(TObject)
  private
    FPId : Integer;
    FSession: IJclIntfArray;
  protected
    FApply:TApplyFunction;
    FValue:TObject;
    procedure Run;
  public
    property Session:IJclIntfArray read FSession;
    property PID:Integer read FPid;

    procedure Send(PID:Integer;data:String);

    constructor Create(Apply:TApplyFunction;Data:TObject);
    destructor Destroy; override;
  end;

function Fork(TheFunction : TApplyFunction; Data:TObject):TPIdList;
//function Fork(Functions : array of TApplyFunction):TPIdList;overload;

implementation

{Funciones}
function Fork(TheFunction : TApplyFunction;Data:TObject):TPIdList;
begin
  TFork.Create(TheFunction, Data);
end;

{
function Fork(Functions : array of TApplyFunction):TPIdList;
var
  funct: TApplyFunction;
begin
    for funct in Functions do
    begin
      TFork.Create(funct);
    end;

    Result := nil;
end;
}
{ TFork }

constructor TFork.Create(Apply:TApplyFunction;Data:TObject);
begin
  FSession := TJclIntfArrayList.Create();
  FPId := 1;
  FApply := Apply;
  
  Run();
end;

destructor TFork.Destroy;
begin
  inherited;
end;

procedure TFork.Run;
var
  value:Integer;
begin
  Value := Integer(FApply(FValue));
  Send(FPId,'Papa');
end;

procedure TFork.Send(PID:Integer;data: String);
begin

end;

end.

Esto es parte del codigo. La idea era usar el algoritmo de map-reduce (muy famoso por lo de google), corutinas y un API similar al session de asp.net para guardar en memoria con llamadas faciles como:

Código Delphi [-]

Send(FPId=1,Datos);

procedure Process(FromPid,Datos)
begin
//Aqui recibe los mensajes
end;

y luego extender para que funcione por red tambien, a lo erlang.

Quede bloqueado con la parte de como usar los messages de windows y otras cosas...
__________________
El malabarista.
Responder Con Cita