Exemplo n.º 1
0
        public void TestLockAndUnlockMutex()
        {
            testName = "TestLockAndUnlockMutex";
            SetUpTest(true);

            /*
             * Open an environment without locking and
             * deadlock detection.
             */
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.FreeThreaded = true;
            envConfig.UseLogging = true;
            envConfig.Create = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);

            // Open a database.
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            TestDB = BTreeDatabase.Open(
                testName + ".db", dbConfig);

            // Get a mutex which will be used in two threads.
            TestMutex = env.GetMutex(true, false);

            // Begin two threads to write records into database.
            Thread mutexThread1 = new Thread(
                new ThreadStart(MutexThread1));
            Thread mutexThread2 = new Thread(
                new ThreadStart(MutexThread2));
            mutexThread1.Start();
            mutexThread2.Start();
            mutexThread1.Join();
            mutexThread2.Join();

            // Free the mutex.
            TestMutex.Dispose();

            // Close all.
            TestDB.Close();
            env.Close();
        }