Page 2 of 2

Posted: Mon Jan 10, 2005 5:40 pm
by PolyVector
I understand why it works, I just was having fun with it :D

err, if you're going to use it in a serious project you'll prolly need it to return the PID of the new thread to the old thread (like the real fork() does)

It will of course require you to call it differently ("If fork()=0")... but will provide more functionality.... I'll get to fixing it...


Update: I've come up with a number of solutions but none of them like the debugger very much :/....

Posted: Mon Jan 10, 2005 6:17 pm
by PolyVector
Here's an update... I added another version of fork() that returns the threadid....

You can still use the original fork() in the same way... i simply added fork_(*ThreadID.LONG) for when you need the threadid...

Code: Select all

Global _ForkRet.l
Procedure _fork(RetAddy.l)
  MOV eax,#True
  CALL RetAddy
  ProcedureReturn #True
EndProcedure
Procedure fork()
  !MOV eax,[esp+20]
  !MOV [v__ForkRet],eax
  CreateThread(@_fork(),_ForkRet)
  ProcedureReturn #False
EndProcedure
Procedure fork_(*ThreadID.LONG)
  !MOV eax,[esp+24]
  !MOV [v__ForkRet],eax
  *ThreadID\l=CreateThread(@_fork(),_ForkRet)
  ProcedureReturn #False
EndProcedure


;/Example:
If fork_(@ThreadID)
  Debug "FORKED"
  MessageRequester("Fork()","Forked :)")
  !RET
EndIf

MessageRequester("","We're Done...")

WaitThread(ThreadID);The debugger doesn't like this line...hrmmmm