Folks,
I have an issue and I would like to share it with you, most likely my understading of things is a little of.
I have an FFI pointer that I populate with a struct that looks like this.
struct DBKey {
tx: ManuallyDrop<Sender<Stuff>>
... other_stuff ...
}
On a separated thread I got a loop that looks like the following.
for message in rx.iter() {
... do_stuff ...
}
log("out of the loop")
The sender in the struct is linked to the receiver in the loop.
The loop is suppose to be an infinite loop, it should just consume messages as they arrive, one by one. Unfortunately it does not and it terminate logging the "out of loop"
message.
I obtain the structure with code that looks like this:
let ptr = unsafe { ... FFI call ...} as *mut DBKey; // get raw pointer
let dbkey = std::ptr::read(ptr); // read the raw pointer
let dbkey = ManuallyDrop::new(dbkey) // avoid to drop the structure
And I obtain the sender like this:
... continuing from above...
let dbkey : ManuallyDrop<DBKey> = { ... function above ... }
Ok(dbkey.tx.clone()) // clone the Sender wrapped in the ManuallyDrop above
I don't understand what is going on.
I log the DBKey drop, and it is not happening. So I never drop the main holder of the Receiver.
However the "infinite loop" terminates, so I guess that somehow all the Senders are dropped, but how?
Can somebody shade some light into this? Or if there are ny ideas on how to debug this kind of problem.