From VisualWorks®, Release 5i.2 of June 8, 2000 on June 23, 2000 at 6:30:45 pm JoinableProcess Kernel Kernel.Process false none result sync Kernel-Processes (none) Kernel.BlockClosure scheduling forkForJoin "Create and schedule a process running the code in the receiver. Answer the new process." | forkedProcess | forkedProcess := JoinableProcess forBlock: self priority: Processor activePriority. forkedProcess resume. ^forkedProcess Core.Integer mathematical functions tfib1 | r | ^self < 2 ifTrue: [1] ifFalse: [r := [(self - 2) tfib1] promise. (self - 1) tfib1 + r value] "Number errorSignal handle: [:ex| ex proceedWith: '??'] do: [ | n t r | n := t := 0. [t <= 30000] whileTrue: [ t := Time millisecondsToRun: [r := n tfib1]. Transcript cr; print: (Array with: n with: t/1000.0 with: r with: r * 1000.0 / t); endEntry. n := n + 1]]" tfib2 | s r1 r2 | ^self < 2 ifTrue: [1] ifFalse: [s := Semaphore new. [r1 := (self - 2) tfib2. s signal] fork. r2 := (self - 1) tfib2. s wait. r1 + r2] "Number errorSignal handle: [:ex| ex proceedWith: '??'] do: [ | n t r | n := t := 0. [t <= 30000] whileTrue: [ t := Time millisecondsToRun: [r := n tfib2]. Transcript cr; print: (Array with: n with: t/1000.0 with: r with: r * 1000.0 / t); endEntry. n := n + 1]]" tfib3 | t | ^self < 2 ifTrue: [1] ifFalse: [t := [(self - 2) tfib3] forkForJoin. (self - 1) tfib3 + t join] "| t n | n := 14. t := Time millisecondsToRun: [r := n tfib3]. Transcript cr; print: (Array with: n with: t/1000.0 with: r with: r * 1000.0 / t); endEntry" "Number errorSignal handle: [:ex| ex proceedWith: '??'] do: [ | n t r | n := t := 0. [t <= 30000] whileTrue: [ t := Time millisecondsToRun: [r := n tfib3]. Transcript cr; print: (Array with: n with: t/1000.0 with: r with: r * 1000.0 / t); endEntry. n := n + 1]]" Kernel.JoinableProcess class instance creation forBlock: aBlock priority: anInteger "Answer an instance of me that has suspended aContext at priority anInteger." | newProcess | newProcess := self new. newProcess suspendedContext: [[newProcess result: aBlock value] on: Process terminateSignal do: [:ex | ex return]. Processor activeProcess primTerminate] newContext. newProcess priority: anInteger. ^newProcess Kernel.JoinableProcess initialization initialize super initialize. sync := Semaphore new Kernel.JoinableProcess synchronization join sync wait. ^result Kernel.JoinableProcess private result: anObject result := anObject. sync signal (ChangeSet current respondsTo: #comment:) ifTrue: [ChangeSet current comment: '"| s n | s := String new writeStream. s cr. n := 14. #(tfib1 tfib2 tfib3) do: [:functionName| | milliseconds result | milliseconds := Time millisecondsToRun: [result := n perform: functionName]. s cr; nextPutAll: functionName; nextPutAll: '' = ''; print: result; nextPutAll: '' in ''; print: milliseconds / 1000.0; cr]. s contents '' tfib1 = 610 in 0.066 tfib2 = 610 in 0.037 tfib3 = 610 in 0.045 ''"']