This discussion is archived
2 Replies Latest reply: May 26, 2009 4:24 AM by 807557 RSS

queue.write()

807557 Newbie
Currently Being Moderated
Hi,

I have a WaitFreeWriteQueue (named "queue") stored in ImmortalMemory, a NHRT running in ScopedMemory writing on queue and a JLT running in the heap and reading from queue.

So if NHRT executes queue.write(someObject); where is this object allocated/saved? This object is created in NHRT, so it is created in ScopedMemory. Passing it with write() to the queue will pass only the reference to this object (stored in ScopedMemory) to the queue (stored in ImmortalMemory) or will the object be copied to ImmortalMemory.

Thanks!
  • 1. Re: queue.write()
    807557 Newbie
    Currently Being Moderated
    The queue object is allocated wherever the current allocation context is when you create the queue.

    The queue's internal storage location depends on the constructor used. The constructor that only takes an int creates the internal storage in ImmortalMemory. The other constructor takes a MemoryArea in which the internal storage is to be allocated.

    The queue only stores a reference to the object.

    So:

    - the queue's internal storage must be able to store a reference to the object

    In this case if the storage is in Immortal and the object in scope then you'll get a MemoryScopeException

    - the reader must also be able to store a reference to the object read.

    This isn't actually spelt out in the spec, but it's the obvious constraint. So if your reader is a plain JLT it will get an exception.

    Basically to communicate between a NHRT using scope, to a JLT using heap you need an intermediary: a RTT using scope that can then copy the object for the JLT. Copy constructors come in handy for objects that you need to copy this way.

    Hope that clarifies things somewhat.

    Edited to add: actually I think there's a problem with the specification of the WFQ classes here. I need to check some details of the spec and our implementation. One thing to keep in mind, and this is something I misunderstood when first encountering the WFQs - the WFQs are a way to communicate between threads in the same memory area, NOT a way to communicate between threads in different memory areas.

    David Holmes

    Edited by: davidholmes on May 25, 2009 6:13 PM
  • 2. Re: queue.write()
    807557 Newbie
    Currently Being Moderated
    Hey David,

    you are right, I get an error when I pass int-, long-, float-values and other objects, but I don't get an exception, when I pass a byte-value to the queue, like:
    byte b = 112;
    queue.write();
    This is what I have done until now, so I even didn't notice the restrictions. No Exception is thrown when one byte is passed. After comments on the existing restrictions I tried to pass an int-value or byte-arrays and I got the expected exceptions.
    'Where is the difference to passing one byte-value? Why do I not get any exceptions?

    Thanks.