You're confusing terms.  "collaborative" (usually called
"cooperative") multi-tasking is like Windows95 -- it's up to each task
to give up the CPU and let something else run.  The tasks "cooperate"
to share the processor.

In "preemptive" multitasking, some master task wakes up at regular
intervals and yanks the CPU out from under whatever task is currently
running.  Most Unixes are this way, and Win2k is claimed to be (but I
sometimes have my doubts).

POE is mostly cooperative closer to the first model; once a state is
running, the kernel waits for it to finish before starting the next
state in the queue.

On Tue, Apr 19, 2005 at 01:38:55PM -0700, sir shz wrote:
> Thanks Rob, but then what is the time-slice for? I thought POE provides the
> time-slicing
> as in a typical operating system (collaborative or pre-emptive
> multi-tasking?). Are you saying that if
> an event handler is blocking (either CPU or IO), POE wont' pause it to
> handle other events? like magic?
> 
> Z.
> 
> ----- Original Message ----- 
> From: "Rob Bloodgood" <[EMAIL PROTECTED]>
> To: "sir shz" <[EMAIL PROTECTED]>; <[email protected]>
> Sent: Tuesday, April 19, 2005 1:13 PM
> Subject: Re: how POE handles long running functions/blocking
> 
> 
> > sir shz wrote:
> > > 1. functions that may take some time (e.g., a long loop)
> >
> > It blocks.
> >
> > > 2. functions that wait on IO (either just waiting, or say reading a huge
> > > file)
> >
> > It blocks.
> >
> > > Does it treat them the same way, by allocating short time slices?
> > >
> > > I was reading a little bit about Python/Twisted, it has a concept of
> > > Deferred,
> > > roughly the above two types of methods will return right away, a
> Deffered
> > > object, then
> > > one registers call backs when the real data comes in. One thing I don't
> like
> > > about
> > > it (as little as I know about it) is that as a programmer, I have to
> decide
> > > this
> > > when I code the function, and when I call it. I'm wondering how this is
> > > deferrent
> > > from the way POE does, and advantages/disadvantages.
> >
> > In order to achieve concurrency, you have to code in a non-blocking
> > fashion.  This means one of: A) working with POE's non-blocking
> > filehandles and sockets, B) forking a child process with Wheel::Run, or
> > C) coding something non-blocking yourself, and using POE's events to
> > perform a slice at a time.  Note that for C), this means your algorithm
> > must explicitly "give up" its timeslice, and be called again (either on
> > I/O on a handle, or by post()ing an event back to yourself).
> >
> > HTH!
> >
> > L8r,
> > Rob
> 

-- 
        Will

Reply via email to