Ejemplo n.º 1
0
        public void run()
        {
            int    i;
            Root   root = (Root)db.Root;
            string tid  = "Thread" + id + ":";

#if USE_GENERICS
            FieldIndex <string, Record> index = root.indices[id % nIndices];
#else
            FieldIndex index = root.indices[id % nIndices];
#endif

            for (i = 0; i < nRecords; i++)
            {
                db.BeginThreadTransaction(TransactionMode.Serializable);
                index.ExclusiveLock();
                Record rec = new Record();
                rec.key = tid + toStr(i);
                index.Put(rec);
                db.EndThreadTransaction();
            }

            index.SharedLock();
            i = 0;
            foreach (Record rec in index.StartsWith(tid))
            {
                Debug.Assert(rec.key.Equals(tid + toStr(i)));
                i += 1;
            }
            Debug.Assert(i == nRecords);
            index.Unlock();

            for (i = 0; i < nRecords; i++)
            {
                index.SharedLock();
                string key = tid + toStr(i);
                Record rec = (Record)index[key];
                Debug.Assert(rec.key.Equals(key));
                index.Unlock();
            }

            for (i = 0; i < nRecords; i++)
            {
                db.BeginThreadTransaction(TransactionMode.Serializable);
                index.ExclusiveLock();
                Record rec = (Record)index.Remove(new Key(tid + toStr(i)));
                rec.Deallocate();
                db.EndThreadTransaction();
            }
        }