OK, here's the deal: I'm trying to create a multi-threading option in my PB DLL. Lets call it Test.dll. This is used in a multi-user environment and works great and very fast but I found a faster way to a certain sub. This new routine is less solid but a lot faster.
So what I want to do is call both the slow and fast routine with the idea like this: if the fast routine does not provide a result, test.dll can wait for the results of the slow routine. This way, my program keeps its speed like it is now but if the fast routine provides results it is a lot faster.
Let me point out that I'm a newbee at multi-threading, read the Jedi piece (and got confused), read the PB help file on THREAD (which is just a real easy program, so didn't do the trick for me).
So I have one base routine from which I call my two routine. Here's some code.
It might be an idea to expand this example a little further later on, cos I'm quit sure that I'm not the only one who's got no clue on how to do this.
So here's the example where global info is passed to the routines
Question:
Must the threads be functions or can they also be sub (like in this example)?
Question:
Why is the result "Both routines didn't provide results"?
Question:
Is it OK to use the Create Thread, but with 0, or should I use 0 and 1? Also for multi-user? Or should I find a way to set an array keeping track of the currently called sub indexes?
I got some more questions, but I leave them for later.
Hope someone can help.
-- Jeroen
------------------
So what I want to do is call both the slow and fast routine with the idea like this: if the fast routine does not provide a result, test.dll can wait for the results of the slow routine. This way, my program keeps its speed like it is now but if the fast routine provides results it is a lot faster.
Let me point out that I'm a newbee at multi-threading, read the Jedi piece (and got confused), read the PB help file on THREAD (which is just a real easy program, so didn't do the trick for me).
So I have one base routine from which I call my two routine. Here's some code.
It might be an idea to expand this example a little further later on, cos I'm quit sure that I'm not the only one who's got no clue on how to do this.
So here's the example where global info is passed to the routines
Code:
#COMPILE EXE "C:\Temp2\MT_TEST.EXE" $INCLUDE "WIN32API.INC" GLOBAL InputString AS STRING GLOBAL OutputString AS STRING SUB FastRoutine(BYVAL x AS LONG) IF LEFT$(InputString, 1) = "$" THEN OutputString = "Fast OK" END IF SLEEP 50 END SUB SUB SlowRoutine(BYVAL x AS LONG) IF RIGHT$(InputString, 1) = "$" THEN OutputString = "Slow OK" END IF SLEEP 5000 END SUB FUNCTION PBMAIN() AS LONG InputString = "$test$" DIM x1 AS LONG DIM x2 AS LONG DIM s1 AS LONG DIM s2 AS LONG ' Start both routines, the slow one first OutputString = "" x1 = GetCurrentThreadID() THREAD CREATE SlowRoutine(0) TO x1 x2 = GetCurrentThreadID() THREAD CREATE FastRoutine(0) TO x2 ' Then wait for the outcome of the fastroutine DO WHILE s1 THREAD STATUS x2 TO s1 LOOP IF OutputString = "" THEN ' if no result, wait for the outcome of the slowroutine DO WHILE s2 THREAD STATUS x1 TO s2 LOOP IF OutputString <> "" THEN MSGBOX "SlowRoutine provided result" + OutputString ELSE MSGBOX "Both routines didn't provide results" END IF ELSE MSGBOX "FastRoutine provided result" + OutputString END IF END FUNCTION
Question:
Must the threads be functions or can they also be sub (like in this example)?
Question:
Why is the result "Both routines didn't provide results"?
Question:
Is it OK to use the Create Thread, but with 0, or should I use 0 and 1? Also for multi-user? Or should I find a way to set an array keeping track of the currently called sub indexes?
I got some more questions, but I leave them for later.
Hope someone can help.
-- Jeroen
------------------
Comment