[Color Computer] Re: [Coco] 6809 Test and Set instruction?

James Diffendaffer jdiffendaffer at yahoo.com
Tue Jul 11 09:13:47 EDT 2006


>> I think he was asking if the 6809 has an instruction similar to the
>> 680x0 test-and-set instruction.  
>> 
>> That is, one instruction that tests the state of a bit and sets it. 
>> The condition code register would let you know the previous state.  
>> This prevents an interrupt or task switch from changing the bit
>> between the time you test it and setting it so that you can restore
>> the proper state later without screwing it up for another task.
>
>That shouldn't be an interrupt problem with the 6809, I wouldn't think, 
>since
>interrupt servicing restores the condition code register to its entry 
>value when the RTI occurs, no?  
>
>Art

Yes and no.  Yes the interrupt will save the CCR.  But that's not the
bit I was talking about.

This is pretty much an OS multi-tasking or multi-cpu thing so you may
not have encountered it.
This will probably be as clear as mud and won't give you the whole
picture but here goes. 

Say you have a shared system resource that only 1 task can use at a
time.  You create a semiphore or lock that tasks can use to see if
it's in use or not.

Task A wants to lock the resource to say it's in use but before it
does it needs to test the lock status to make sure it's not already in
use.  
Suppose it was unlocked or a bit flag was not set to begin with.
The test instruction executes BUT an interrupt takes place and makes a
task switch to Task B before the flag is set by the instruction that
locks the resource.

Task B also wants to lock the same resource.  It tests the status,
then locks it by setting the bit.  If Task B finishes and unlocks the
resource before Task A continues... no problem.

But suppose a task switch takes place and Task A continues before Task
B is done.
Task A had tested the status but the interrupt that triggered the task
switch took place and the lock status is now different from what it
was during the test.
Task A doesn't know the resource is in use, locks it and attempts to
use it.  The resource may be in an unknown state and using it may be
unpredictable.  Once Task A is done it UNLOCKS the resource and now
any other task that attempts to access the resource doesn't know it's
in use by Task B either.  Task A may also have left the resource in a
different state than Task B is expecting giving unpredictable results.

The worst part is that this only happens when a task switch takes
place between the test and set making it almost impossible to find.
Imagine trying to track something that rare down.

If you have a single instruction that tests and sets the bit flag you
eliminate the problem.  The same thing is true if you disable and
enable interrupts around the test and set instructions.  No task
switch takes place until your done so there's no confustion.

Like I said... clear as mud.







------------------------ Yahoo! Groups Sponsor --------------------~--> 
Check out the new improvements in Yahoo! Groups email.
http://us.click.yahoo.com/6pRQfA/fOaOAA/yQLSAA/CFFolB/TM
--------------------------------------------------------------------~-> 

Brought to you by the 6809, the 6803 and their cousins! 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ColorComputer/

<*> To unsubscribe from this group, send an email to:
    ColorComputer-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the Coco mailing list