crossbeam icon indicating copy to clipboard operation
crossbeam copied to clipboard

Pinning custom Collector

Open vorner opened this issue 6 years ago • 3 comments

Hello

I have trouble with using a custom Collector inside a data structure I'm writing (contrie).

I'm not sure if I'm just reading the docs wrong, or if the API is actually missing. I've also tried to look into crossbeam-skiplist, but that part seems to not be implemented yet.

I would like to put a Collector inside the data structure, for two reasons:

  • Being able to perform all delayed destructions in the drop, so I can store non-'static types safely.
  • My iterator type contains a Guard, so if someone holds it for too long or leaks it, there are going to be problems with memory reclamation in the whole application. Using a private one could at least localize the impact.

I can put the Collector into the struct. However, to get a Guard, I first need to register a LocalHandle. I assume it is relatively expensive call, so I don't think it is meant to be called for each pin call, eg in each method of the map. On the other hand, if I create one and want to reuse it, I have nowhere to put it and asking the user to keep it around doesn't look convenient either.

What is the expected way to do this? What is the plan for crossbeam-skiplist (which, according to a TODO) seems to plan to do a similar thing? If the API is missing, is there the design for it somewhere (depending on my free time and complexity of the surrounding code, I might try to implement it)?

vorner avatar Jun 11 '19 06:06 vorner

Note: I'm just another crossbeam user. It seems like you might want to cache a local handle it some sort of thread local thing which you can then call pin on. Also interested in this since I'm the author of ccl and The Concurrent Map Competition and I'm looking to do something similiar for one of the datastructures I'm currently developing.

xacrimon avatar Jun 12 '19 21:06 xacrimon

Yes, but the usual thread local variable is somewhat globalish thing ‒ If I have two map instances, they don't get a separate thread local variable each. Having a map ThreadId→handle inside map feels somewhat like a chicken-egg problem, doesn't delete the ones for deleted threads and adds another map lookup ☹. So that doesn't sound like a proper solution.

So I simply hope there's some way how it is supposed to be done, maybe just not yet written :-).

vorner avatar Jun 13 '19 05:06 vorner

Is nobody able to answer? Or, at least, tell me nobody thought about a way yet? :-(

vorner avatar Jul 07 '19 09:07 vorner