<html>

<head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Timestamp Scheduler</title>
</head>

<body>



<p align="left"><font size="6" color="#FF0000"><span lang="en-ca"><b>&nbsp; 
 
</b></span><b>&nbsp;&nbsp;&nbsp; </b></font><span lang="en-ca">
<font size="6" color="#FF0000"><b>Scheduler-II</b></font></span></p>

<div align="left">
  <pre><b><font color="#ff0000" size="5">A. <span lang="en-ca">Second </span>Edition</font></b></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>This is just for fun. You know, in DBMS you can find almost everything in OS. Scheduler is one of them. Actually</b></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>I want to implement a small simulation of transaction-control algorithm in DBMS which uses time-stamp of </b></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>transactions and database elements. But starting this environment takes me a whole day. </b></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>And it is not only for fun, as I found a small problem in the rule of textbook. Even though it seems trivial, but</b></span></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><b>as a protocol, it will cause deadlock which I consider to be big mistake in sense of protocol!!!</b></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">B</span>.<span lang="en-ca"><a name="problem"></a>The problem</span></font></b></pre>
</div>
<div align="left">
  <span lang="en-ca"><b>In DBMS, there is basically two big schemes for 
  transaction control: locking and timestamp. I want </b></span>
  <p><span lang="en-ca"><b>to simulate timestamp first. Then we have first to 
  define what is a transaction. After that you </b></span></p>
  <p><span lang="en-ca"><b>need to define what is a task.</b></span></p>
  <p><span lang="en-ca"><b>I changed my idea of &quot;taskitem&quot; which becomes little 
  use now. Since I am aiming to implement Round-</b></span></p>
  <p><span lang="en-ca"><b>Robin, there is no need for me to record this &quot;TaskItem&quot;.</b>
  </span></p>
  <b><font color="#ff0000" size="5"><span lang="en-ca"><a name="explain"></a>C</span>.<span lang="en-ca">The
  </span></font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>idea of 
  program</b></font></span></div>
<div align="left">
  　</div>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>There is a big common thing 
between task pool and transaction pool---they can both be implemented as a kind 
of</b></font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>special queue. Therefore, I 
defined a template queue. </b></font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>Then I plan to write 
scheduler whose scheduling scheme would most probably round-robin.&nbsp; </b>
</font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>Probably many people would 
find difficult in understanding the purpose of many functions. Actually almost 
every</b></font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>time I try to write some 
program, it is like an adventure for me in C++. This time, I found I don't need 
to </b></font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>stick to the idea of class. 
Instead, struct and class are basically same thing in defining member functions
</b></font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>except in struct all are 
all public, and in class all are private, by default.</b></font></span></p>
<p ALIGN="LEFT"><span lang="en-ca"><font size="2"><b>I implement &quot;abort&quot; by 
recording previous timestamp and committed status in each &quot;Task&quot; structure. </b>
</font></span></p>
<div align="left">
  <pre><b><font color="#ff0000" size="5">D.<span lang="en-ca"><a name="Method"></a>The </span>major functions</font></b></pre>
</div>
<div align="left">
  <pre>　</pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">E</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>Further improvement</b></font></span></pre>
</div>
<div align="left">
  <pre>　</pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">F</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>File listing</b></font></span></pre>
</div>
<div align="left">
  <pre><font size="3"><b><span lang="en-ca">1. scheduler.h</span></b></font></pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3"><b>2</b></font></span><font size="3"><b><span lang="en-ca">. scheduler.</span></b></font><span lang="en-ca"><font size="3"><b>cpp</b></font></span></pre>
</div>
<div align="left">
  <pre><font size="3"><b><span lang="en-ca">1. main.cpp</span></b></font></pre>
</div>
<div align="left">
  <pre>　</pre>
</div>
<div align="left">
  <pre><span lang="en-ca"><font size="3" color="#FF0000"><b>file name: scheduler.h</b></font></span></pre>
</div>
<pre>#include &lt;stdio.h&gt;

const int MaxTaskCount=6;
const int MaxTransCount=4;
const int MaxElementCount=4;
const int MaxTaskItemCount=300;


//forward declaration
class Scheduler;

enum TaskType
{
	Read, Write, Commit, Abort
};

//this is database elements
struct Element
{
	int ID;//should be same as index
	int readStamp;
	int writeStamp;
	bool committed;
	void display();
};	

//read or write
struct Task
{
	int element;//the index of element
	TaskType taskType;
	int prevStamp;
	bool prevCommitted;
	void display();
};

//
struct Transaction
{
	int timeStamp;
	int count;
	int current;
	Task tasks[MaxTaskCount];
	void moveNext(int&amp; index);
	bool haveNext();
	Task* operator[](int index){return tasks+index;}
	Transaction&amp; operator=(Transaction&amp; other);
	void display();
};


	
//a universal queue, because I find transpool, and taskpool is 
//similar in someway, I can let them both inherit from a 
//common ancester, but template is another choice.
template&lt;class T, int MaxListLength&gt;
class Queue
{
	friend class Scheduler;
protected:
	T list[MaxListLength];
	int count;
	int front, back, current;
public:
	Queue();
	inline int getCount(){return count;}
	bool enqueue(T*&amp; outPtr);//add at front+1
	bool dequeue(T*&amp; outPtr);//remove from back
	T* next();
	void display();
	//passing a compare function pointer
	int search(bool (*compare)(T* left, T* right), T* key);
	int find(T* item);
	T* operator[](int index);
	void remove(int index);//remove the indexed, and shift array
};

//it is difficult to remove by returning pointers, instead of index
struct TaskItem
{
	Transaction* transID;//should be the pointer, instead of timestamp
	int taskIndex;
	void display();
};

bool taskItemCompare(TaskItem* left, TaskItem* right);

class TransPool
{
	friend class Scheduler;
private:
	Queue&lt;Transaction, MaxTransCount&gt; list;
public:
	TransPool();
	void createTrans(int timeStamp);
	Transaction* next();
	void removeAny();
	void destroyTrans();
	void display(){ list.display();}
};
	
class TaskPool
{
	friend class Scheduler;
private:
	Queue&lt;TaskItem, MaxTaskItemCount&gt; list;
public:
	TaskItem* getTaskItem();
	void addItem(Transaction* transPtr);
	void removeAny();//this is for debugging
	void update(int transID);//put status on
	void display(){ list.display();}
	TaskItem* next(){return list.next();}
};

class Scheduler
{
private:
	int timeStamp;
	Element elements[MaxElementCount];
	TransPool transPool;
	TaskPool taskPool;
	void delayItem(TaskItem* item);
	void abortItem(TaskItem* item);
	void commitItem(TaskItem* item);
	void doExecTask(TaskItem* item);
	void removeAny();
	void createTrans();
	void tickTimer();
	void execTask();
	void addTask();
	void destroyTrans();
	void showStatus();
public:
	void display();
	void doJob(int step);
	Scheduler();
};

template&lt;class T, int MaxListLength&gt;
void Queue&lt;T, MaxListLength&gt;::display()
{
	for (int i=0; i&lt;count; i++)
	{
		list[(back+i)%MaxListLength].display();
	}
}


template&lt;class T, int MaxListLength&gt;
void Queue&lt;T, MaxListLength&gt;::remove(int index)
{	
	if (index&lt;count)
	{
		for (int i=index; i&lt;count-1; i++)
		{
			*(this-&gt;operator[](i))= *(this-&gt;operator[]((i+1)));					
		}
		count--;
		if (current==(back+index)%MaxListLength)
		{
			if (index&gt;0)
			{
				current=(back+index-1)%MaxListLength;
			}
			//current still equal back
		}
		front=(back+count)%MaxListLength;//different module
		
	}
}

template&lt;class T, int MaxListLength&gt;
int Queue&lt;T, MaxListLength&gt;::find(T* item)
{
	for (int i=0; i&lt;count; i++)
	{
		if (list+(back+i)%MaxListLength==item)
		{
			return i;
		}
	}
	return -1;
}

//compare is a function pointer
template&lt;class T, int MaxListLength&gt;
int Queue&lt;T, MaxListLength&gt;::search(bool (*compare)(T* left, T* right), T* key)
{	
	for (int i=0; i&lt;count; i++)
	{
		if (compare(list+(back+i)%MaxListLength, key))
		{
			return i;
		}
	}
	return -1;
}

template&lt;class T, int MaxListLength&gt;
T* Queue&lt;T, MaxListLength&gt;::operator [](int index)
{
	if (index&lt;count)
	{
		return list+(back+index)%MaxListLength;
	}
	else
	{
		return NULL;
	}
}

template&lt;class T, int MaxListLength&gt;
Queue&lt;T, MaxListLength&gt;::Queue()
{
	front=back=current=count=0;
}

template&lt;class T, int MaxListLength&gt;
bool Queue&lt;T, MaxListLength&gt;::enqueue(T*&amp; outPtr)
{
	if (count&lt;MaxListLength)
	{
		count++;
		outPtr=list+front;//return first
		front=(front+1)%MaxListLength;		
		return true;
	}
	else
	{
		return false;
	}
}

template&lt;class T, int MaxListLength&gt;
bool Queue&lt;T, MaxListLength&gt;::dequeue(T*&amp; outPtr)
{
	if (count&gt;0)
	{
		count--;
		outPtr=list+back;
		if (current==back)
		{
			back=(back+1)%MaxListLength;
		}
		back=(back+1)%MaxListLength;
		return true;
	}
	else
	{
		return false;
	}
}

template&lt;class T, int MaxListLength&gt;
T* Queue&lt;T, MaxListLength&gt;::next()
{		
	if (count==0)
	{
		return NULL;
	}
	//advance until meet front
	current=(current+1)%MaxListLength;
	if (current==front)
	{
		current=back;
	}
	return list+current;
}



</pre>
<pre>
</pre>
<pre><span lang="en-ca"><font size="3" color="#FF0000"><b>file name: scheduler.cpp</b></font></span></pre>
<pre>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &quot;scheduler.h&quot;

const int ScheduleTaskNumber=4;

char* typeString[]=
{
	&quot;Read&quot;, &quot;Write&quot;, &quot;Commit&quot;, &quot;Abort&quot;
};

bool taskItemCompare(TaskItem* left, TaskItem* right)
{
	return left-&gt;transID==right-&gt;transID;
}	


Scheduler::Scheduler()
{
	timeStamp=0;
	for (int i=0; i&lt;MaxElementCount; i++)
	{
		elements[i].ID=i;
		elements[i].readStamp=elements[i].writeStamp=0;
		elements[i].committed=true;
	}

}

void Scheduler::doJob(int step)
{
	for (int i=0; i&lt;step; i++)
	{
		tickTimer();
		switch(rand()%ScheduleTaskNumber)
		{
		case 0:
			transPool.createTrans(timeStamp);
			break;
		case 2:
			execTask();
			break;
		case 3: 
			//removeAny();
			break;
		}
		//showStatus();
	}
}

//for debugging
void Scheduler::removeAny()
{
	transPool.removeAny();
}

void Scheduler::addTask()
{
	Transaction* ptr;
	//if transpool is not empty
	if ((ptr=transPool.next())!=NULL)
	{
		//ptr is an input pointer param
		taskPool.addItem(ptr);
	}
}

void Scheduler::showStatus()
{
	printf(&quot;time is %d;\n*****************************\n&quot;, timeStamp);
	printf(&quot;transaction pool is:\n&quot;);
	transPool.display();
	//printf(&quot;task pool is:\n&quot;);
	//taskPool.display();
}

void Scheduler::display()
{
	showStatus();
}


void Scheduler::tickTimer()
{
	timeStamp++;
	if (timeStamp%20==0)
	{
		showStatus();
	}
}

void Scheduler::doExecTask(TaskItem* item)
{
	Transaction* tranPtr;
	Task* taskPtr;
	Element* elemPtr;
	
	tranPtr=item-&gt;transID;//the pointer
	taskPtr=tranPtr-&gt;tasks+item-&gt;taskIndex;
	elemPtr=elements+taskPtr-&gt;element;//element is array of Element in scheduler
	
	printf(&quot;\n*************************\nbefore action element %c is:&quot;, elemPtr-&gt;ID+'A');
	elemPtr-&gt;display();


	switch(taskPtr-&gt;taskType)
	{
	case Read:
		//compare the transaction timestamp with write timestamp of element
		if (tranPtr-&gt;timeStamp&gt;=elemPtr-&gt;writeStamp)
		{
			//two cases, if element is committed
			if (tranPtr-&gt;timeStamp!=elemPtr-&gt;writeStamp&amp;&amp;!elemPtr-&gt;committed)
			{
				//realizable, but have to delay it until it is committed
				//delayItem(item);
				printf(&quot;transaction %d is delayed when attempted reading element %c\n&quot;, 
					tranPtr-&gt;timeStamp,	elemPtr-&gt;ID+'A');
			}
			else
			{
				//update read timestamp of element if necessary
				if (tranPtr-&gt;timeStamp&gt;elemPtr-&gt;readStamp)
				{	
					//record previous read stamp
					taskPtr-&gt;prevStamp=elemPtr-&gt;readStamp;
					taskPtr-&gt;prevCommitted=elemPtr-&gt;committed;
					elemPtr-&gt;readStamp=tranPtr-&gt;timeStamp;								
				}
				printf(&quot;transaction %d is successful when attempted reading element %c\n&quot;, 
						tranPtr-&gt;timeStamp,	elemPtr-&gt;ID+'A');
					//it can be finished, or committed
				commitItem(item);
			}
		
		}
		else
		{
			//unrealizable, abort
			abortItem(item);
			printf(&quot;transaction %d is aborted when attempted reading element %c\n&quot;, 
				tranPtr-&gt;timeStamp,	elemPtr-&gt;ID+'A');
		}
		break;
	case Write:
		//two cases, if timestamp is later than readstamp of element
		if (tranPtr-&gt;timeStamp &gt;= elemPtr-&gt;readStamp)
		{
			//if no other later transaction has written
			if (tranPtr-&gt;timeStamp &gt;= elemPtr-&gt;writeStamp)
			{
				//record time stamp and committed status for rollback
				taskPtr-&gt;prevCommitted=elemPtr-&gt;committed;
				taskPtr-&gt;prevStamp=elemPtr-&gt;writeStamp;
				elemPtr-&gt;writeStamp=tranPtr-&gt;timeStamp;
				elemPtr-&gt;committed=false;
				printf(&quot;transaction %d is successful when attempt writing element %c\n&quot;, 
					tranPtr-&gt;timeStamp,	elemPtr-&gt;ID+'A');			
				commitItem(item);								
			}
			else
			{
				if (elemPtr-&gt;committed)
				{
					printf(&quot;transaction %d is ignored when attempt writing element %c\n&quot;,
						tranPtr-&gt;timeStamp, elemPtr-&gt;ID+'A');
					//ignore should be able to be finished
					taskPtr-&gt;prevCommitted=elemPtr-&gt;committed;
					taskPtr-&gt;prevStamp=elemPtr-&gt;writeStamp;
					commitItem(item);
				
				}
				else
				{
					//delayItem(item);
					printf(&quot;transaction %d is delayed when attempted writing element %c\n&quot;, 
						tranPtr-&gt;timeStamp,	elemPtr-&gt;ID+'A');
				}
			}
		}
		else
		{
			//unrealizable, abort
			abortItem(item);
			printf(&quot;transaction %d is aborted when attempted writing element %c\n&quot;, 
				tranPtr-&gt;timeStamp,	elemPtr-&gt;ID+'A');
		}
		break;
	default:
		printf(&quot;strange thing is here\n**********************\n&quot;);
		break;
	}
	printf(&quot;after action element %c is:&quot;, elemPtr-&gt;ID+'A');
	elemPtr-&gt;display();
	//it is committed or 
}

void Scheduler::abortItem(TaskItem* item)
{
	Transaction* tranPtr;
	Task* taskPtr;
	tranPtr=item-&gt;transID;
	
	for (int i=tranPtr-&gt;current; i&gt;=0; i--)
	{
		taskPtr=tranPtr-&gt;tasks+i;
		if (taskPtr-&gt;taskType==Read)
		{
			elements[taskPtr-&gt;element].readStamp=taskPtr-&gt;prevStamp;
		}
		else
		{
			elements[taskPtr-&gt;element].writeStamp=taskPtr-&gt;prevStamp;
		}
		elements[taskPtr-&gt;element].committed=taskPtr-&gt;prevCommitted;
	}
	tranPtr-&gt;current=0;
}




void Scheduler::commitItem(TaskItem* item)
{
	Transaction* tranPtr;
	int index;
	tranPtr=item-&gt;transID;
	if (tranPtr-&gt;count==item-&gt;taskIndex+1)
	{
		printf(&quot;transaction %d is committed\n&quot;, tranPtr-&gt;timeStamp);
		for (int i=0; i&lt;tranPtr-&gt;count; i++)
		{
			if (tranPtr-&gt;tasks[i].taskType==Write)
			{
				elements[tranPtr-&gt;tasks[i].element].committed=true;
			}
		}
		if ((index=transPool.list.find(tranPtr))!=-1)
		{
			transPool.list.remove(index);
		}
	}
	else
	{
		tranPtr-&gt;current++;
	}

	/*
	while ((index=taskPool.list.search(taskItemCompare, item))!=-1)
	{
		taskPool.list.remove(index);
	}
	*/
	//showStatus();

}


void Scheduler::execTask()
{
	Transaction* tranPtr;
	TaskItem item;

	//if there is transaction
	if (transPool.list.count&gt;0)
	{
		tranPtr=transPool.list.next();
		{
			item.transID=tranPtr;
			item.taskIndex=tranPtr-&gt;current;
			doExecTask(&amp;item);
		}
	}

	/*
	TaskItem* item;

	item=taskPool.next();
	if (item!=NULL)
	{
		doExecTask(item);
	}
	*/

	//taskPool.display();
	//taskPool.removeAny();
	//taskPool.display();
}

void TaskPool::removeAny()
{
	int index;
	if (list.getCount()&gt;0)
	{
		index=rand()%list.getCount();
		printf(&quot;remove taskpool of task with index of %d\n&quot;, index);
		list.remove(index);
	}
}

//want to remove finished tasks
//later.....
void TaskPool::update(int transID)
{
	TaskItem* ptr;
	for (int i=0; i&lt;list.getCount(); i++)
	{
		ptr=list.next();
		if (ptr!=NULL)
		{
			//if (ptr-&gt;ti
		}
	}
}

//this is like a scheduler's bookkeeper which records all
//tasks to be done
void TaskPool::addItem(Transaction* transPtr)
{
	TaskItem* ptr;
	int index;
	if (!transPtr-&gt;haveNext())
	{
		return;
	}
	if (list.enqueue(ptr))
	{
		ptr-&gt;transID=transPtr;
		transPtr-&gt;moveNext(index);
		ptr-&gt;taskIndex=index;
	}
}

void Element::display()
{
	printf(&quot;Element ID=%c; read stamp=%d; write stamp=%d; committed=%c\n&quot;,
		ID+'A', readStamp, writeStamp, committed?'T':'F');
}

bool Transaction::haveNext()
{
	return current+1&lt;count;
}

void Transaction::moveNext(int&amp; index)
{
	index=current;
	current++;
}


void Task::display()
{
	printf(&quot;Task element=%c, type=%s&quot;, element+'A', typeString[taskType]);
	printf(&quot;Element previous timestamp=%d, previous committed=%c\n&quot;,
		prevStamp, prevCommitted?'T':'F');
}

void Transaction::display()
{
	printf(&quot;Transaction timestamp=%d; count=%d; current=%d;\n&quot;, timeStamp,
		count, current);
	for (int i=0; i&lt;count; i++)
	{
		tasks[i].display();
	}
}

void TaskItem::display()
{
	printf(&quot;Task item: transaction time stamp=%d; taskindex of %d\n&quot;, transID-&gt;timeStamp, 
		taskIndex);
	printf(&quot;the task is:&quot;);
	transID-&gt;tasks[taskIndex].display();
}

TransPool::TransPool()
{

}

Transaction&amp; Transaction::operator =(Transaction&amp; other)
{
	timeStamp=other.timeStamp;
	count=other.count;
	current=other.current;
	for (int i=0; i&lt;count; i++)
	{
		tasks[i]=other.tasks[i];//copy
	}
	return *this;
}

//this is mainly for debugging
void TransPool::removeAny()
{
	int index;
	if (list.getCount()&gt;0)
	{
		list.display();
		index=rand()%list.getCount();
		printf(&quot;transpool remove transaction of index of %d\n&quot;, index);
		list.remove(index);
		list.display();
	}
}


void TransPool::createTrans(int timeStamp)
{
	Transaction* ptr;
	if (list.enqueue(ptr))
	{
		ptr-&gt;timeStamp=	timeStamp;
		ptr-&gt;count=rand()%MaxTaskCount+1;
		for (int i=0; i&lt;ptr-&gt;count; i++)
		{
			ptr-&gt;tasks[i].taskType=rand()%2==0?Read:Write;
			ptr-&gt;tasks[i].element=rand()%MaxElementCount;
			ptr-&gt;tasks[i].prevCommitted=false;
			ptr-&gt;tasks[i].prevStamp=0;
		}
		ptr-&gt;current=0;	
		
	}
	//else do nothing
}


void TransPool::destroyTrans()
{
	Transaction* ptr;
	if (list.dequeue(ptr))
	{
		printf(&quot;transaction with timestamp of %d destroyed\n&quot;, ptr-&gt;timeStamp);
	}
}

Transaction* TransPool::next()
{
	return list.next();
}



</pre>
<pre>
</pre>
<pre><span lang="en-ca"><font size="3" color="#FF0000"><b>file name: main.cpp</b></font></span></pre>
<pre>#include &quot;scheduler.h&quot;
#include &lt;time.h&gt;
#include &lt;stdlib.h&gt;



int main()
{
	srand(time(0));
	Scheduler S;
	S.doJob(100);
	return 0;
}</pre>
<pre>　</pre>
<pre></pre>
<pre></pre>
<pre><span lang="en-ca"><font color="#0000FF"><b>How to run?</b></font></span></pre>
<pre><span lang="en-ca"><font color="#0000FF"><b>1.This is just a startup of environment. So, I just implement the display function for debugging.</b></font></span></pre>
<p><br>
*************************<br>
before action element A is:Element ID=A; read stamp=0; write stamp=0; 
committed=T<br>
transaction 2 is successful when attempted reading element A<br>
after action element A is:Element ID=A; read stamp=2; write stamp=0; committed=T<br>
<br>
*************************<br>
before action element B is:Element ID=B; read stamp=0; write stamp=0; 
committed=T<br>
transaction 2 is successful when attempted reading element B<br>
after action element B is:Element ID=B; read stamp=2; write stamp=0; committed=T<br>
<br>
*************************<br>
before action element D is:Element ID=D; read stamp=0; write stamp=0; 
committed=T<br>
transaction 8 is successful when attempted reading element D<br>
after action element D is:Element ID=D; read stamp=8; write stamp=0; committed=T<br>
time is 20;<br>
*****************************<br>
transaction pool is:<br>
Transaction timestamp=2; count=5; current=2;<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=8; count=4; current=1;<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=C, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=9; count=1; current=0;<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=13; count=2; current=0;<br>
Task element=B, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
<br>
*************************<br>
before action element D is:Element ID=D; read stamp=8; write stamp=0; 
committed=T<br>
transaction 9 is successful when attempted reading element D<br>
transaction 9 is committed<br>
after action element D is:Element ID=D; read stamp=9; write stamp=0; committed=T<br>
<br>
*************************<br>
before action element B is:Element ID=B; read stamp=2; write stamp=0; 
committed=T<br>
transaction 13 is successful when attempt writing element B<br>
after action element B is:Element ID=B; read stamp=2; write stamp=13; 
committed=F<br>
<br>
*************************<br>
before action element C is:Element ID=C; read stamp=0; write stamp=0; 
committed=T<br>
transaction 25 is successful when attempted reading element C<br>
after action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=T<br>
<br>
*************************<br>
before action element A is:Element ID=A; read stamp=2; write stamp=0; 
committed=T<br>
transaction 2 is successful when attempted reading element A<br>
after action element A is:Element ID=A; read stamp=2; write stamp=0; committed=T<br>
<br>
*************************<br>
before action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=T<br>
transaction 8 is aborted when attempted writing element C<br>
after action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
time is 40;<br>
*****************************<br>
transaction pool is:<br>
Transaction timestamp=2; count=5; current=3;<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=8; count=4; current=0;<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=C, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=13; count=2; current=1;<br>
Task element=B, type=WriteElement previous timestamp=0, previous committed=T<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=25; count=4; current=1;<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
<br>
*************************<br>
before action element A is:Element ID=A; read stamp=2; write stamp=0; 
committed=T<br>
transaction 13 is successful when attempt writing element A<br>
transaction 13 is committed<br>
after action element A is:Element ID=A; read stamp=2; write stamp=13; 
committed=T<br>
time is 60;<br>
*****************************<br>
transaction pool is:<br>
Transaction timestamp=2; count=5; current=3;<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=8; count=4; current=0;<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=C, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=25; count=4; current=1;<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
<br>
*************************<br>
before action element A is:Element ID=A; read stamp=2; write stamp=13; 
committed=T<br>
transaction 25 is successful when attempt writing element A<br>
after action element A is:Element ID=A; read stamp=2; write stamp=25; 
committed=F<br>
<br>
*************************<br>
before action element A is:Element ID=A; read stamp=2; write stamp=25; 
committed=F<br>
transaction 2 is aborted when attempted reading element A<br>
after action element A is:Element ID=A; read stamp=0; write stamp=25; 
committed=T<br>
<br>
*************************<br>
before action element D is:Element ID=D; read stamp=0; write stamp=0; 
committed=T<br>
transaction 8 is successful when attempted reading element D<br>
after action element D is:Element ID=D; read stamp=8; write stamp=0; committed=T<br>
<br>
*************************<br>
before action element D is:Element ID=D; read stamp=8; write stamp=0; 
committed=T<br>
transaction 25 is successful when attempted reading element D<br>
after action element D is:Element ID=D; read stamp=25; write stamp=0; 
committed=T<br>
<br>
*************************<br>
before action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
transaction 71 is delayed when attempted reading element C<br>
after action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
<br>
*************************<br>
before action element A is:Element ID=A; read stamp=0; write stamp=25; 
committed=T<br>
transaction 2 is aborted when attempted reading element A<br>
after action element A is:Element ID=A; read stamp=0; write stamp=25; 
committed=T<br>
time is 80;<br>
*****************************<br>
transaction pool is:<br>
Transaction timestamp=2; count=5; current=0;<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=8; count=4; current=1;<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=C, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=25; count=4; current=3;<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=WriteElement previous timestamp=13, previous committed=T<br>
Task element=D, type=ReadElement previous timestamp=8, previous committed=T<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=71; count=4; current=0;<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=D, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=F<br>
<br>
*************************<br>
before action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
transaction 8 is aborted when attempted writing element C<br>
after action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
<br>
*************************<br>
before action element B is:Element ID=B; read stamp=0; write stamp=13; 
committed=T<br>
transaction 25 is successful when attempted reading element B<br>
transaction 25 is committed<br>
after action element B is:Element ID=B; read stamp=25; write stamp=13; 
committed=T<br>
time is 100;<br>
*****************************<br>
transaction pool is:<br>
Transaction timestamp=2; count=5; current=0;<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=A, type=WriteElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=8; count=4; current=0;<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=T<br>
Task element=C, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=71; count=4; current=0;<br>
Task element=C, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=D, type=WriteElement previous timestamp=0, previous committed=F<br>
Task element=B, type=ReadElement previous timestamp=0, previous committed=F<br>
Task element=D, type=ReadElement previous timestamp=0, previous committed=F<br>
Transaction timestamp=99; count=1; current=0;<br>
Task element=D, type=WriteElement previous timestamp=0, previous committed=F<br>
<br>
*************************<br>
before action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
transaction 71 is delayed when attempted reading element C<br>
after action element C is:Element ID=C; read stamp=25; write stamp=0; 
committed=F<br>
　</p>

<pre></pre>

<pre>　</pre>

<pre></pre>

<pre></pre>

<pre></pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                   
&nbsp;&nbsp;&nbsp; <a href="PocketRuler.htm">                  







                       <img src="picture/back.gif" style="border: medium none" alt="back.gif (341 bytes)" width="32" height="35"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="index.htm">
<img src="picture/up.gif" style="border: medium none" alt="up.gif (335 bytes)" width="35" height="32"></a>       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                         
<img src="picture/next.gif" style="border: medium none" alt="next.gif (337 bytes)" width="32" height="35">          


</p>

</body>

</html>