fork()

Share your advanced PureBasic knowledge/code with the community.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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 :/....
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

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