TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Rusty Plant
from: Michael Douglass
date: 1994-06-16 14:05:20
subject: Os/2 Pm Programmers-= 1/

RP>Have you figured out how to pass parameters to threads? I
  >like Guideslines so far, but it seems to be missing several
  >key Os/2 functions in it's JOT language. So far I have been
  >forced to intermix C with JOT. (ex DosSleep,Semaphores,etc).

Ok, I just had to go look.  You are right, you can't do that...  Ok, if
you can be POSTIVE that there will only be ONE instance of the threaded
code at any ONE time, (can you even run a thread more than once at any
one time?) then you can simply use global variables (a structure would
probably be better to keep it all tied up).

If you want to run multiple instances, try the following: (Note, this is
off the top of my head, and may contain bugs.) MAX_INSTANCES is the
number of times the thread can be running at any one time.

STRUCTURES:
struct threadInfo
{
        SHORT threadInUse
        SHORT myShort1, myShort2
        STRING myString
}

GLOBAL VARIABLES:
threadInfo myThreadInfo[MAX_INSTANCES]
SHORT startingThread       ;0=no >0 gives index into myThreadInfo

FUNCTION TO CALL THREAD:

VOID callThread1(SHORT myShort1, SHORT myShort2, STRING myString)
  SHORT loop
;If a thread is currently starting, enter a loop until thread
;completely starts
  while startingThread0
  endwhile

; hault any other attempts to start this thread
  startingThread=1

;Find an index in myThreadInfo that is not in use
  for loop=0 to MAX_INSTANCES-1
        if myThreadInfo[loop].threadInUse=0
                break
        endif
  endfor
;Check for maximum instances
  if loop=MAX_INSTANCES
        ERROR- MAXIMUM INSTANCES ALREADY RUNNING (Do whatever)
  endif
;Set data you want passed
  myThreadInfo[loop].myShort1=myShort1
  myThreadInfo[loop].myShort2=myShort2
  myThreadInfo[loop].myString1=myString1
  myThreadInfo[loop].threadInUse=1
;set startingThread to loop+1 so the thread knows where to find
;the data it needs in myThreadInfo.  (The +1 is to distinguish 0
;from meaning that a new thread is not being started)
  startingThread=loop+1

;START THE THREAD HERE WITH THE THREAD CALLS
end


THREAD CODE:
VOID thread1 ()

  SHORT useIndex
; Get the index from startingThread (-1 to counteract the +1 above)
  useIndex=startingThread-1
; Allow other instances to start
  startingThread=0

; data can now be referenced by myThreadInfo[useIndex].myShort1, or
; .myShort2, or .myString

;
;  YOUR THREAD CODE HERE
;

; release data from myThreadInfo for future use
  myThreadInfo[useIndex].threadInUse=0

; KILL YOUR THREAD HERE.
end



RP>I have seenn object windows mentioned in the docs, but
  >can't find any information on how to use them in
  >Guidelines. Any ideas?

No idea.

I hope the code above helps...  It took me a while to enter it all.

(Continued to next message)
___
 .Mike's Mail Internet:   MICHAEL.DOUGLASS{at}LCHANCE.SAT.TX.US
              
--- Maximus/2 2.01wb

* Origin: The Rock BBS--410Meg, i486/33, ZyXEL v32bis. (1:387/31)
SEEN-BY: 54/54 620/243 632/348 640/820 690/660 711/409 413 430 807 808 809
SEEN-BY: 711/934 712/353 623 713/888 800/1 2442/0
@PATH: 387/31 1102 3615/50 229/2 2442/0 711/409 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.