I've been having weird problems with strings and threads.
Given a and b, both of which are "string" type (ansistring, to be precise), what does a:=b; actually do?
Does it allocate the space for a and copy b's content, or does it create a reference from a to b? Or something else?
See an example below.
The procedure is getting called from various threads, and the strings keep disappearing and losing the last character in them.
Both case A and case B give problems, but they differ a bit.
type dstkrec=record
c:boolean;
n,f:string;
end;
var dstack:array[0..DSTKS-1]of dstkrec;
procedure add(const fn,dir:string);
var i,c:integer;
begin
mutex_lock(ar_mx);
c:=-1;
for i:=0 to DSTKS-1 do if not dstack[i].c then begin c:=i; break; end;
if c<>-1 then begin
dstack[c].c:=true;
{$ifdef casea}
//Case A:
dstack[c].f:=fn;
dstack[c].n:=dir;
{$else}
//Case B:
setlength(dstack[c].f,length(fn));
move(fn[1],dstack[c].f[1],length(fn));
setlength(dstack[c].n,length(dir));
move(dir[1],dstack[c].n[1],length(dir));
{$endif}
end;
mutex_release(ar_mx);
end;