Page 1 of 1

List argument in a thread

Posted: Tue Sep 07, 2010 8:21 pm
by y3an
Hello,

I tried to use a List as argument in a Thread and get a "memory access error"... Do I miss something or it's just impossible ?

Sorry, it's hard form me to explain better in English. :x


Code: Select all

Structure Detail
  
  ID.w : N.w
  C1.w : C2.w
  X1.w : X2.w 
  Y1.w : Y2.w
  
EndStructure


NewList Format_Menu.Detail() : AddElement(Format_Menu())

                    Format_Menu()\ID   = SpriteID :  Format_Menu()\N       = NBoucle
                    
                    Format_Menu()\C1   = BaseC    :  Format_Menu()\C2      = C
                    Format_Menu()\X1   = BaseX    :  Format_Menu()\X2      = X
                    Format_Menu()\Y1   = BaseY    :  Format_Menu()\Y2      = Y  



Procedure Do_Format_Menu( List Format.Detail() )
  
  ResetList(Format()) 
  
 ; While NextElement(Format())
     
  ; For A = 0 To Format()\N 
  ;   *Menu\ID[ Format()\ID+A ] = Format()\C1 + Format()\C2
  ;   *Menu\X [ Format()\ID+A ] = Format()\X1 + Format()\X2*A 
  ;   *Menu\Y [ Format()\ID+A ] = Format()\Y1     
  ; Next A
   
 ; Wend
                      
EndProcedure

CreateThread(@Do_Format_Menu(), Format_Menu())


Repeat : ForEver

Re: List argument in a thread

Posted: Tue Sep 07, 2010 9:28 pm
by Trond
You can't do that.

Re: List argument in a thread

Posted: Wed Sep 08, 2010 4:05 am
by netmaestro
A thread takes a pointer as parameter, which means you can literally do anything you want, it's just a matter of how you frame it:

Code: Select all

Structure STUFF
  List numbers.i()
EndStructure

*mystuff.STUFF = AllocateMemory(SizeOf(STUFF))
InitializeStructure(*mystuff, STUFF)

For i=1 To 10
  AddElement(*mystuff\numbers())
  *mystuff\numbers() = i*100
Next

Procedure MyThread(*list.STUFF)
  ForEach *list\numbers()
    Debug *list\numbers()
  Next
EndProcedure

tid = CreateThread(@MyThread(), *mystuff)
WaitThread(tid)
And Bob's your uncle. But no, a thread procedure will not accept a list as argument directly. You could also pass together with the list an array, a map, and umpteen other odds and ends, as long as it's all contained in the same structure, the pointer of which you pass to the thread procedure. Feel the PURE POWER!!! ... are you feeling it?

Re: List argument in a thread

Posted: Wed Sep 08, 2010 6:48 pm
by y3an
Thanks Trond for the first approach.. ! :wink:

And Thanks a lot Netmaestro for answering the subsequent question, that I failed to ask ! :lol:
Now that it seams clear as in your code, I feel Purely ashamed with my question :lol:


Thanks a lot ! Now I can see the sun blueing, feel the sky shining and I vomit rainbows ! I feel it ! The Pure experience !