This project is read-only.
1
Vote

Lazy<T> and nested lock causes Execution Timeout Error

description

Hi there!
 
I encountered another problem using Alpaca.
I get an Execution Timeout Error with the hint to an "This is a strong indication of a livelock". But to be honest, I've not idea where this might occur.
Any help is highly welcome :-)
 
Here's my test code:
 
using System;
using System.Threading.Tasks;
using Microsoft.Concurrency.TestTools.UnitTesting;
 
namespace MOCTestProject
{
public class AlpacaTest5
{
    [DataRaceTestMethod]
    public void LazyTest()
    {            
        var lazy1 = new Lazy<Item>(() => new Item("1"));
 
        Item item1 = null;
        Item item2 = null;
 
        Parallel.Invoke(
            () => { item1 = lazy1.Value; },
            () => { item2 = lazy1.Value;  }
            );
 
        Assert.IsNotNull(item1);
        Assert.IsNotNull(item2);             
    }
 
    public class Item
    {
        private readonly object syncObject = new object();

        public Item(string text)
        {
            lock (syncObject)
                Text = text;
        }
 
        public string Text { get; private set; }
    }
}
 
-Matthias

comments