Deadlocks in GraphEngine

139 views Asked by At

Working with GraphEngine for a while I very often find myself with a deadlocked thread while doing some operation against GraphEngine. Nested calls are definitely not on the menu. But now I encountered something strange:

foreach(long cellID ...)
{
    byte[] buffer;

    // the next line will block on the 54th call...
    Global.LocalStorage.LoadCell(cellID, out buffer);
}

Suspecting a non-existing cellID I wrapped the call with

if(Global.LocalStorage.Contains(cellID))
{ ... }

But now this call blocks indefinitly.

Is this a bug? or

Under which conditions would the call block?

Cheerio, Andreas.

1

There are 1 answers

4
L. H. On BEST ANSWER

@Andreas Hassmann, I had met a similar issue, so I guess your trouble may be caused by the ... in the foreach-loop.

I used an iterator like Global.LocalStorage.xxxCell_Accessor_Selector().Select(c => c.CellID.Value). In this case, the locks of the storage haven't been released which causes the deadlock when Global.LocalStorage.LoadCell() acquires the locks.

If your problem is exact the same as mine, the solution will be to apply .ToList() to the iterator.

Here are my codes to reproduce your problem.

The TSL:

cell struct MyCell 
{
    int A; 
}

The codes:

for (int i = 0; i < 100; i++)
{
    MyCell mc = new MyCell(i);
    Global.LocalStorage.SaveMyCell(i, mc);
}

var ids = Global.LocalStorage.MyCell_Accessor_Selector().Select(c => c.CellID.Value);

Console.WriteLine("1 start.");
foreach (long cellID in ids.ToList())
{
    byte[] buffer;
    Global.LocalStorage.LoadCell(cellID, out buffer);
    Console.WriteLine(cellID);
}
Console.WriteLine("1 done.");

Console.WriteLine("2 start.");
foreach (long cellID in ids) 
{
    byte[] buffer;
    Global.LocalStorage.LoadCell(cellID, out buffer);
    Console.WriteLine(cellID);
}
Console.WriteLine("2 done.");