Hi, folks.
I'm not newto Pascal programming, but to thread-programming.
I want to pass an Array filled with Byte-values to a threaded function, but al i tried doe'nt work, yet.
Here is a minimal example of my current try:
{$mode obfpc}
program miniexp;
uses
{$ifdef UNIX} cthreads; {$endif}
type
TByteArray = Array of Byte;
PByteArray = ^TByteArray;
TArrIndex = Byte;
var
AnArray : TByteArray; (* Array to pass *)
ArrAddr : PByteArray; (* addres of AnArray *)
lc : TArrIndex; (* loopcounter *)
thisd : TThreadid; (* threadid *)
(*this function just pronts the passed array.*)
function miniexp(pt : pointer) : ptrint;
var
toPrint : TByteArray;
idx : TArrIndex;
begin
toPrint := PByteArray(pt);
for idx := low(toPrint) to high(toPrint) do
begin
writeln(toPrint[idx]);
end;
miniexp := 0;
EndThread;
end;
Begin
SetLength(AnArray, 10); (*set array to proper length*)
(* fill the array*)
randomize;
for lc := low(AnArray) to high(AnArray) do
begin
AnArray[lc] := (random(521) mod 256);
end;
(*The following works, but does'nt pass the full array. *)
ArrAddr := @AnArray;
thid := BeginThread(TThreadfunc(@miniexp), pointer(ArrAddr));
WaitForThreadTerminate(thid, 1000000);
End.
(*of miniexample.*)
Any suggestions arewelcome.
With greets and respect,
jddev.