[quote=“logician, post:7, topic:2877, full:true”]
Is there a problem with writing a wrapper that registers the thread on the first call to the allocation function?
[/quote]
That’s what I’d do. The GC-crate should offer its own spawn function. I’m fairly sure the type system can express a special Send type, to make sure that you don’t send GCable types across normally spawned threads. Here’s something along which lines it should work.
```rust
impl !Send for Gc {}
unsafe impl GSend for T where T: Send {}
unsafe impl GSend for Gc {}
struct Hack<RES: Send + 'static, F: GSend + FnOnce() -> RES + 'static>(F);
unsafe impl<RES: Send + 'static, F: GSend + FnOnce() -> RES + 'static> Send for Hack<RES, F> {}
fn spawn<F, T>(f: F) -> JoinHandle
where F: FnOnce() -> T, F: GSend + 'static, T: Send + 'static
{
let hack = Hack(f);
// init gc here
std::thread::spawn(move || (hack.0)())
}
<strike>Works in the [Playground](http://is.gd/ZaMGAl)</strike>
UPDATE: This doesn't work with the regular std-threading-tools like channels or mutexes... :( (see http://is.gd/YYz4xW for the attempt)