⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.13
Server IP:
109.199.105.153
Server:
Linux connect.inboxifs.com 5.15.0-152-generic #162-Ubuntu SMP Wed Jul 23 09:48:42 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.2.29
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
View File Name :
page-fiber_md.ri
U:RDoc::TopLevel[ i I" fiber.md:EFcRDoc::Parser::Markdowno:RDoc::Markup::Document:@parts[*S:RDoc::Markup::Heading: leveli: textI" Fiber;To:RDoc::Markup::Paragraph;[I"<Fibers provide a mechanism for cooperative concurrency.;TS; ; i;I"Context Switching;To;;[I"Fibers execute a user-provided block. During the execution, the block may call <code>Fiber.yield</code> or <code>Fiber.transfer</code> to switch to another fiber. <code>Fiber#resume</code> is used to continue execution from the point where <code>Fiber.yield</code> was called.;To:RDoc::Markup::Verbatim;[I"�#!/usr/bin/env ruby puts "1: Start program." f = Fiber.new do puts "3: Entered fiber." Fiber.yield puts "5: Resumed fiber." end puts "2: Resume fiber first time." f.resume puts "4: Resume fiber second time." f.resume puts "6: Finished." ;T:@format: rubyo;;[I":This program demonstrates the flow control of fibers.;TS; ; i;I"Scheduler;To;;[I"^The scheduler interface is used to intercept blocking operations. A typical implementation would be a wrapper for a gem like <code>EventMachine</code> or <code>Async</code>. This design provides separation of concerns between the event loop implementation and application code. It also allows for layered schedulers which can perform instrumentation.;To;;[I"1To set the scheduler for the current thread:;To; ;[I"*Fiber.set_scheduler(MyScheduler.new) ;T;;o;;[I"TWhen the thread exits, there is an implicit call to <code>set_scheduler</code>:;To; ;[I"Fiber.set_scheduler(nil) ;T;;S; ; i;I"Interface;To;;[I"1This is the interface you need to implement.;To; ;[I"�class Scheduler # Wait for the specified process ID to exit. # This hook is optional. # @parameter pid [Integer] The process ID to wait for. # @parameter flags [Integer] A bit-mask of flags suitable for `Process::Status.wait`. # @returns [Process::Status] A process status instance. def process_wait(pid, flags) Thread.new do Process::Status.wait(pid, flags) end.value end # Wait for the given file descriptor to match the specified events within # the specified timeout. # @parameter event [Integer] A bit mask of `IO::READABLE`, # `IO::WRITABLE` and `IO::PRIORITY`. # @parameter timeout [Numeric] The amount of time to wait for the event in seconds. # @returns [Integer] The subset of events that are ready. def io_wait(io, events, timeout) end # Sleep the current task for the specified duration, or forever if not # specified. # @param duration [Numeric] The amount of time to sleep in seconds. def kernel_sleep(duration = nil) end # Block the calling fiber. # @parameter blocker [Object] What we are waiting on, informational only. # @parameter timeout [Numeric | Nil] The amount of time to wait for in seconds. # @returns [Boolean] Whether the blocking operation was successful or not. def block(blocker, timeout = nil) end # Unblock the specified fiber. # @parameter blocker [Object] What we are waiting on, informational only. # @parameter fiber [Fiber] The fiber to unblock. # @reentrant Thread safe. def unblock(blocker, fiber) end # Intercept the creation of a non-blocking fiber. # @returns [Fiber] def fiber(&block) Fiber.new(blocking: false, &block) end # Invoked when the thread exits. def close self.run end def run # Implement event loop here. end end ;T;;o;;[I"tAdditional hooks may be introduced in the future, we will use feature detection in order to enable these hooks.;TS; ; i;I"Non-blocking Execution;To;;[I"�The scheduler hooks will only be used in special non-blocking execution contexts. Non-blocking execution contexts introduce non-determinism because the execution of scheduler hooks may introduce context switching points into your program.;TS; ; i ;I"Fibers;To;;[I"BFibers can be used to create non-blocking execution contexts.;To; ;[I"�Fiber.new do puts Fiber.current.blocking? # false # May invoke `Fiber.scheduler&.io_wait`. io.read(...) # May invoke `Fiber.scheduler&.io_wait`. io.write(...) # Will invoke `Fiber.scheduler&.kernel_sleep`. sleep(n) end.resume ;T;;o;;[I"_We also introduce a new method which simplifies the creation of these non-blocking fibers:;To; ;[I"BFiber.schedule do puts Fiber.current.blocking? # false end ;T;;o;;[I"�The purpose of this method is to allow the scheduler to internally decide the policy for when to start the fiber, and whether to use symmetric or asymmetric fibers.;To;;[I"5You can also create blocking execution contexts:;To; ;[I"NFiber.new(blocking: true) do # Won't use the scheduler: sleep(n) end ;T;;o;;[I"UHowever you should generally avoid this unless you are implementing a scheduler.;TS; ; i ;I"IO;To;;[I"/By default, I/O is non-blocking. Not all operating systems support non-blocking I/O. Windows is a notable example where socket I/O can be non-blocking but pipe I/O is blocking. Provided that there _is_ a scheduler and the current thread <em>is non-blocking</em>, the operation will invoke the scheduler.;TS; ; i ;I" Mutex;To;;[I"^The <code>Mutex</code> class can be used in a non-blocking context and is fiber specific.;TS; ; i ;I"ConditionVariable;To;;[I"jThe <code>ConditionVariable</code> class can be used in a non-blocking context and is fiber-specific.;TS; ; i ;I"Queue / SizedQueue;To;;[I"}The <code>Queue</code> and <code>SizedQueue</code> classes can be used in a non-blocking context and are fiber-specific.;TS; ; i ;I"Thread;To;;[I"hThe <code>Thread#join</code> operation can be used in a non-blocking context and is fiber-specific.;T: @file@:0@omit_headings_from_table_of_contents_below0