-
Continuation from the discussion on pull request #4. The section of my code using LCell is the following:
If this could avoid the overhead of a thread lock, the error that I'm dealing with has to do with lifetimes inside of a closure. cannot infer an appropriate lifetime for lifetime parameter 'id in function call due to conflicting requirements Is there any way to use the LCell in a multithreaded context (instead of a mutex) with the goal of avoiding thread locks? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What GhostCell provides (or TCell or QCell for that matter) is the ability to move the ownership from the cell itself to the 'owner' (which is called a 'token' in the GhostCell paper). So to make this work for your code, you'd need to divide the image into The fundamental problem with this code as it stands is that it only has one owner, and the threads can't all share the same owner mutably. In that section 1.2 it does actually say "To achieve the same for our doubly-linked list, we would use RwLock<GhostToken<'id>>." So you could do that, but that isn't going to be any more efficient than just putting a RwLock or Mutex around the whole Vec. Where GhostCell provides an advantage in section 1.2 is converting N rw-locks into 1 rw-lock, but in your case you already have just 1 rw-lock. However if you're going to split up the image into |
Beta Was this translation helpful? Give feedback.
-
Also, I should add that starting with LCell and LCellOwner (or equivalently GhostCell) makes things a lot more complicated, because the lifetime errors can be very confusing. If you had started with QCell, the errors would have been clearer and you might have figured out all this for yourself. QCell and TCell have the same borrowing characteristics as LCell and GhostCell. (TLCell is different) |
Beta Was this translation helpful? Give feedback.
What GhostCell provides (or TCell or QCell for that matter) is the ability to move the ownership from the cell itself to the 'owner' (which is called a 'token' in the GhostCell paper). So to make this work for your code, you'd need to divide the image into
num_threads
parts before spawning all the threads. Each part needs to have its own owner. Then one owner would be passed to each thread.The fundamental problem with this code as it stands is that it only has one owner, and the threads can't all share the same owner mutably. In that section 1.2 it does actually say "To achieve the same for our doubly-linked list, we would use RwLock<GhostToken<'id>>." So you could do that, but that isn'…