crossbeam-rs / crossbeam

Tools for concurrent programming in Rust
Apache License 2.0
7.44k stars 470 forks source link

Pinning custom Collector #390

Open vorner opened 5 years ago

vorner commented 5 years ago

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:

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)?

xacrimon commented 5 years ago

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.

vorner commented 5 years ago

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 commented 5 years ago

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