EnableExplicit
Structure someProcedure_parameters
helloWorld$
number.l
isRead.l
EndStructure
Procedure _someProcedure(*parameters.someProcedure_parameters) ;the thread
Protected helloWorld$, number
helloWorld$ = *parameters\helloWorld$
number = *parameters\number
*parameters\isRead = #True ;tell it that it now can delete the memory area we read from
Delay(1000) ;wait a second (just too prove that it works)
Debug "But we did get the parameters:"
Debug helloWorld$
Debug number
EndProcedure
Procedure someProcedure(helloWorld$, number) ;the thread caller (so you can use it as a normal procedure almost)
Protected parameters.someProcedure_parameters ;create the structure containing the parameters
parameters\helloWorld$ = helloWorld$
parameters\number = number
parameters\isRead = #False
CreateThread(@_someProcedure(),@parameters) ;send the thread a pointer to our structure
Repeat
Until parameters\isRead ;do not quit (delete the structure) before it has read it
EndProcedure
someProcedure("Hello World!",123456)
Debug "Thread caller has now ended."
Delay(2000)
Last edited by Joakim Christiansen on Thu Feb 11, 2010 9:41 am, edited 3 times in total.
I like logic, hence I dislike humans but love computers.
EnableExplicit
Structure someProcedure_parameters
helloWorld$
number.l
EndStructure
Procedure _someProcedure(*parameters.someProcedure_parameters) ;the thread
Protected helloWorld$, number
helloWorld$ = *parameters\helloWorld$
number = *parameters\number
ClearStructure(*parameters, someProcedure_parameters)
FreeMemory(*parameters)
Delay(1000) ;wait a second (just too prove that it works)
Debug "But we did get the parameters:"
Debug helloWorld$
Debug number
EndProcedure
Procedure someProcedure(helloWorld$, number) ;the thread caller (so you can use it as a normal procedure almost)
Protected *parameters.someProcedure_parameters ;create the structure containing the parameters
*parameters = AllocateMemory(SizeOf(someProcedure_parameters))
*parameters\helloWorld$ = helloWorld$
*parameters\number = number
CreateThread(@_someProcedure(), *parameters) ;send the thread a pointer to our structure
EndProcedure
someProcedure("Hello World!",123456)
Debug "Thread caller has now ended."
Delay(2000)
Thanks Fred! I didn't think of that!
And... ClearStructure() is not documented in the help file Fred EDIT: Well, actually it is, but hitting F1 on it doesn't work.
should be something in the help docs about passing multiple parameters into a thread
Agreed.
I like logic, hence I dislike humans but love computers.
Not intending to get off topic, but its sort of on topic in a way. The help says this:
"ClearStructure free the memory of a structured memory area. This is useful when the structure contains strings which have been allocated internally by PureBasic. 'Structure' is the name of the structure which should be used to perform the clearing. There is no internal check to ensures than the structure match the memory area. This function is for advanced users only and should be used with care."
This part in particular : " This function is for advanced users only and should be used with care."
What does that mean? Is there an example of when it would not be applicapable to use?
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Since the memory at the address pointed to will be cleared it can easily cause a problem.
The structure parameter let it know how much memory to clear, so if you give it the wrong information there it could overwrite memory it shouldn't. And therefore it should only be used by users who knows what they are doing I guess.
I like logic, hence I dislike humans but love computers.