You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "Digy (JIRA)" <ji...@apache.org> on 2008/07/19 13:41:31 UTC

[jira] Commented: (LUCENENET-135) Race condition in DocumentsWriter.UpdateDocument

    [ https://issues.apache.org/jira/browse/LUCENENET-135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12614980#action_12614980 ] 

Digy commented on LUCENENET-135:
--------------------------------

I haven't found a nice solution yet. This example below shows  the bug.

DIGY

{code}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class MonitorTest
    {
        static void Main(string[] args)
        {
            MonitorTest m = new MonitorTest();
            m.Start();
        }

        void Start()
        {
            Thread t1 = new Thread(new ThreadStart(GetThreadState));
            Thread t2 = new Thread(new ThreadStart(GetThreadState));
            Thread t3 = new Thread(new ThreadStart(FinishDocument));

            t1.IsBackground = t2.IsBackground = t3.IsBackground = true;
            t1.Start();
            t2.Start();
            Thread.Sleep(1000);
            t3.Start();

            Console.WriteLine("Press ENTER to Exit");
            Console.ReadLine();
        }

        int ThreadCountInCriticalSection = 0;

        void GetThreadState()
        {
            lock (this)
            {
                ThreadCountInCriticalSection++;
                if (ThreadCountInCriticalSection > 1) 
                    Console.WriteLine(ThreadCountInCriticalSection + " threads in critical section");
                
                Monitor.Wait(this); //Unblocks lock(this)
                Thread.Sleep(10);

                ThreadCountInCriticalSection--;
                Console.WriteLine("Leaving Critical section");
            }
        }
                
        void FinishDocument()
        {
            lock (this)
            {
                //Since This thread starts 1 sec later, it should never reach to this point
                ThreadCountInCriticalSection++;
                if (ThreadCountInCriticalSection > 1) 
                    Console.WriteLine(ThreadCountInCriticalSection + " threads in critical section");

                Monitor.PulseAll(this); //Unblocks Monitor.Wait
            }
        }
    }
}

{code}


> Race condition in DocumentsWriter.UpdateDocument
> ------------------------------------------------
>
>                 Key: LUCENENET-135
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-135
>             Project: Lucene.Net
>          Issue Type: Bug
>         Environment: 2.3.1
>            Reporter: Digy
>         Attachments: DocumentsWriter-Temp.patch
>
>
> There is a race condition in DocumentsWriter.UpdateDocument. Locking the whole method solves the problem but this is not what  is intended in java version
> (testcase:  Index/TestIndexWriter/TestDocumentsWriterExceptionThreads)
> I am working on it.
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.