Hi.
I use one SDL_CreateThread in my games, but now I need several Threads and I want to use param 2 in SDL_CreateThread to specify the data that hade use in each thread.
When I use only one thread the code is:
Code:
uses SDL;
var
thread: PSDL_Thread;
returnValue: Integer;
function thread_func(): Integer;
begin
// do threading here
WriteLn('Start Thread');
SDL_Delay(5000);
WriteLn('End Thread');
result := 1; // thread leaves and return this value
end;
begin
returnValue := 0;
thread := SDL_CreateThread(@thread_func, NIL);
SDL_WaitThread(thread, returnValue);
WriteLn('Thread returns code ',returnValue);
SDL_Quit;
WriteLn('ByeBye ;)');
end.
but now with several thread I test this:
Code:
uses SDL;
var
thread: PSDL_Thread;
returnValue: Integer;
function thread_func(MyData:TList): Integer;
begin
// do threading here
while MyData.Count > 0 do
begin
WriteLn('....');
MyDate.Delete(0);
end;
SDL_Delay(5000);
WriteLn('End Thread');
result := 1; // thread leaves and return this value
end;
begin
returnValue := 0;
MyList : TList.Create;
MyList.Add(....);
thread := SDL_CreateThread(@thread_func, MyList);
SDL_WaitThread(thread, returnValue);
WriteLn('Thread returns code ',returnValue);
SDL_Quit;
WriteLn('ByeBye ;)');
end.
but parameter2 do not pass to function, MyDate (in function) is always to NIL
How are passed the parameter 2?
Thanks
Bookmarks