This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimal timing slice , Thread qn


On Wed, Jan 19, 2005 at 02:58:02PM -0800, steve smith wrote:
> > Why should read get control?
> because at the end of the write thread execution both read and write
> threads are ready to execute. and since they are of same priority
> levels shouldnt control alternate between both of them if they are
> both ready (?)

A time slice will happen when a thread has run for its full time
slice.  At that point the schedular will see if there is any other
thread with equal priority which can run.

Your code does

        while (1)
                lock(mutex)
                do_somehting()
                unlock(mutex);

What will normally happen is that the timeslice will expire somewhere
in do_something. Since the mutex is locked, the other thread is not
executable, its blocked on the mutex. So this thread continues to run
in a new timeslice.

The only way a context switch can happen is if the timeslice happens
after the unlock but before the lock. Given that thats just a few
instructions, and do_something is probably 1000 or 10,000 of
instructions, the probability of a timeslice happening there is very
low.

        Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]