Page 1 of 1
					
				Structures as a parameter for a thread
				Posted: Sat Dec 31, 2005 1:27 pm
				by phuckstepp
				I'm trying to create a thread and pass through multiple parameters by using a structure and a pointer to the structure, but for some reason the PB compiler reports back:
This variable doesn't have a 'Structure'
Can anyone help? I've put below the relevant snippets from the code.
Code:
Structure at the top of the file
Code: Select all
Structure threadInfo
  dir.l
  folder.s  
EndStructure
Thread creation from a procedure called after a button click
Code: Select all
myThreadData.threadInfo
myThreadData\dir=num(f)
myThreadData\folder=myPath$
myThread(f) = CreateThread(@ThreadProcess(), @myThreadData ) 
The threads main procedure
Code: Select all
Procedure ThreadProcess(*a.threadInfo)
 passedNum=a\dir
 myPath$=a\folder
...
EndProcedure
Thanks for any help
[/code]
 
			 
			
					
				
				Posted: Sat Dec 31, 2005 1:37 pm
				by Pupil
				you forget to use '*a\...' instead you use 'a\...' which doesn't have a structure. In PB the variables '*a' and 'a' are two different variables.
			 
			
					
				
				Posted: Sat Dec 31, 2005 2:21 pm
				by phuckstepp
				So simple. Thanks
			 
			
					
				
				Posted: Sat Dec 31, 2005 5:41 pm
				by blueznl
				be carefull when using pointers INSIDE structures though...
http://www.xs4all.nl/~bluez/datatalk/pu ... d_pointers 
			 
			
					
				
				Posted: Mon Jan 02, 2006 5:50 pm
				by NoahPhense
				Can you post a small working example of that .. 
- np
			 
			
					
				
				Posted: Mon Jan 02, 2006 7:15 pm
				by blueznl
				follow the link above, scroll down a little, and look for the section 'pointers in structures', it's a working example
			 
			
					
				
				Posted: Mon Jan 02, 2006 7:59 pm
				by NoahPhense
				No I'm looking for a simple example of threads with
pointers..  Just like above, where he is passing multiple params via
the pointer.
- np
			 
			
					
				
				Posted: Mon Jan 02, 2006 8:41 pm
				by blueznl
				ah, haven't done threads yet in the survival guide, sorry 

 
			 
			
					
				
				Posted: Tue Jan 03, 2006 4:36 am
				by NoahPhense
				Code: Select all
; ok did my own.. and added an array to be passed to the threads
; structure for the array
Structure people
  name.s
  age.l
EndStructure
; the array
Dim emp.people(9) ; 10 people (0-9)
Declare threadedProcedure(*a.people)
; delay between thread launching
dlay.l = 200
; lets load up the array
Gosub loadArray
; core --------------------------------------------------------------
If OpenConsole()
  ; process 9 threads here
  For x = 0 To 8
    CreateThread(@threadedProcedure(), @emp(x)) : Delay(dlay)
  Next x
  
  ; lets keep thread 10 for last
  threadID9 = CreateThread(@threadedProcedure(), @emp(9)) : Delay(dlay)
  WaitThread(threadID9)
  Print("enter..") : enter$ = Input() ; shows over
  CloseConsole()  
EndIf
End
; procedures --------------------------------------------------------
Procedure threadedProcedure(*a.people)
  PrintN(*a\name)
  PrintN(Str(*a\age))
  PrintN("")
EndProcedure
; loadarray ---------------------------------------------------------
loadArray:
  Restore NameData
    For x = 0 To 9
      Read tmpStr.s
      emp(x)\name = tmpStr
    Next x
  Restore AgeData
    For x = 0 To 9
      Read tmpLng.l
      emp(x)\age = tmpLng
    Next x
Return
; datasection -------------------------------------------------------
DataSection
  NameData:
    Data.s "Bob", "Fred", "Mike", "Mark", "Ben", "Daniella", "John"
    Data.s "Curtis", "Alain", "Jorge"
  AgeData:    
    Data.l 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
- np