Structures as a parameter for a thread

Windows specific forum
phuckstepp
User
User
Posts: 19
Joined: Tue Dec 27, 2005 12:10 pm
Location: United Kingdom
Contact:

Structures as a parameter for a thread

Post 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]
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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.
phuckstepp
User
User
Posts: 19
Joined: Tue Dec 27, 2005 12:10 pm
Location: United Kingdom
Contact:

Post by phuckstepp »

So simple. Thanks
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

be carefull when using pointers INSIDE structures though...

http://www.xs4all.nl/~bluez/datatalk/pu ... d_pointers
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Can you post a small working example of that ..

- np
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

follow the link above, scroll down a little, and look for the section 'pointers in structures', it's a working example
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post 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
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

ah, haven't done threads yet in the survival guide, sorry :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

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