List argument in a thread

Just starting out? Need help? Post your questions and find answers here.
y3an
User
User
Posts: 56
Joined: Sun Mar 09, 2008 6:06 am

List argument in a thread

Post 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
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: List argument in a thread

Post by Trond »

You can't do that.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: List argument in a thread

Post 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?
BERESHEIT
y3an
User
User
Posts: 56
Joined: Sun Mar 09, 2008 6:06 am

Re: List argument in a thread

Post 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 !
Post Reply