How do you pass a type into a thread?
BlitzMax Forums/BlitzMax Beginners Area/How do you pass a type into a thread?
| ||
I'm starting a thread but I can't figure out how to actually pass or retrieve information from it. If I add an extra var to the Function I get an error. Anyone shed some light on how to pass a type into a Thread Function? |
| ||
You should post your code. |
| ||
Thats what the CreateThread() data parameter is for ;) It goes something like this: Local userdata:String[] = [ "my", "user", "data" ] Local thread:TThread = CreateThread( Byte Ptr threadFunc, userdata) Delay 1000 WriteStdout "after-thread=" For Local s:String = EachIn userdata WriteStdout s + " " Next WriteStdout "~n" Function threadFunc:Object( userdata:String[]) WriteStdout "inside-thread=" For Local s:String = EachIn userdata WriteStdout s + " " Next WriteStdout "~n" userdata[1] = "altered" EndFunction Or just use Object and cast it yourself... |
| ||
That's funny because that's what I thought too. I pretty much did what you did but with a type and it was throwing errors like heck. I'll do some more testing. But basically what I'm after is getting it to where I have a pool of threads and I assign tasks to them. And when they are done they clean up and go back into the pool for reuse. I'll do more testing when I get home in about 14 hours :(. The military does have it's drawbacks. Massively long hours at work. Thanks for the help. |