Witam, kiedyś już poruszałem ten temat i wydawało mi się że go zrozumiałem,
przyszło co do czego i lipa, odszukałem stary post ale nie dał mi on wyjaśnienia...
Chciałbym przekazać do nowego wątku zmienną dynamiczną...
Napisałem przykład czegoś takiego w C i działa:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void ThreadFunc(int *i) {
printf("%d", *i);
free(i);
}
void main() {
int *i = (int*) malloc(4);
*i = 1234;
unsigned long tid;
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, i, 0, &tid);
getchar();
}
Natomiast w Delphi ciągle wyskakuje access violation w procedurze ThreadFunc...
program Project1;
{$APPTYPE CONSOLE}
uses Windows;
type
PInteger = ^Integer;
var
TId: Cardinal;
I: PInteger;
procedure ThreadFunc(P: Pointer);
begin
WriteLn(PInteger(P)^);
FreeMem(P);
end;
begin
GetMem(I, 4);
I^ := 1234;
CreateThread(nil, 0, @ThreadFunc, I, 0, TId);
ReadLn;
end.
Co źle robię ?