Weird behaviour in C++ OneToOneConcurrentArrayQueue

188 views
Skip to first unread message

Dominik Konik

unread,
Jul 25, 2016, 3:23:03 PM7/25/16
to mechanical-sympathy
Hi,

I seem to have found some weird behavior in the c++ version of the OneToOneConcurrentArrayQueue. I've simplified and added the code at the end to show the issue and make it (hopefully) reproducible. 

Summary of Issue: If I offer and poll more times than the requestedCapacity that I pass in to the constructor, the queue "freezes" and only returns null pointer from the poll function. 

C++ Code: 
int main(){
        //If you change numIterations to 1025, the program freezes
        int numIterations = 1023;

int sizeOfArr = 1024;
aeron::driver::concurrent::OneToOneConcurrentArrayQueue<byte*> queue(sizeOfArr);
byte* arr = new byte [sizeOfArr];
byte** arrPtr = &arr;

for(int i = 0; i < numIterations; ++i){
queue.offer(arrPtr)

while((arrPtr = queue.poll()) == nullptr){
cout << "In poll loop" << endl;
}

//Not get optimized away
  for(int k = 0; k < sizeOfArr; ++k){
(*arrPtr)[k] = (*arrPtr)[k] + 1;
}
}
}

Here is a Java program that does virtually the same thing, which behaves as expected and doesn't freeze up, regardless of the number of Iterations that are done:

public class QueueTester {

  public static void main(String[] args) {

    int sizeOfArray = 1024;

    final Queue<byte[]> queue = new OneToOneConcurrentArrayQueue<byte[]>(1024);

    byte[] arr = new byte[sizeOfArray];


    for (int i = 0; i < 10000; i++) {

      queue.offer(arr)


      while ((arr = queue.poll()) == null) {

        System.out.println("In poll loop");

      }


      // Prevent Aggressive optimizations

      for (int k = 0; k < sizeOfArray; k++) {

        arr[k] = (byte) (arr[k] + 1);

      }

    }

  }

}


Was wondering if anyone had any input on this? Thanks!

Todd Montgomery

unread,
Jul 26, 2016, 1:43:55 PM7/26/16
to mechanical-sympathy
Martin did a fix for this in https://github.com/real-logic/Aeron/commit/57edbb28e9c0520cce59495a698fd909c9105b9c


Thanks for pointing it out! Let us know if this seems to work OK.

--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages