salva has asked for the wisdom of the Perl Monks concerning the following question:
The issue I am facing is that Net::SSH2 wraps the objects in the underlaying libssh2 library using the sv_setref_pv function that just creates a new SV and places the pointer into the IV slot. When a thread containing Net::SSH2 objects creates a new thread, those SVs are cloned but the objects they point to are not. Later, when in some thread the object gets out of scope and its DESTROY method is called, the underlaying object is deallocated leaving the clones with a dangling pointer and after that, any use of those, including destroying then, may cause the application to crash.
So, my question is, what mechanism could be used to avoid that. How XS/C objects can be wrapped in a multi-thread friendly way?
The only viable way I can envision in to use magic for that, replacing the sv_setref_pv wrapping for one using a magic structure of type PERL_MAGIC_ext (~) with svt_dup pointing to a callback that does reference counting.
Are there any easier ways for doing it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multi-thread friendly object life-time handling for XS modules
by syphilis (Archbishop) on Nov 06, 2017 at 12:54 UTC | |
|
Re: Multi-thread friendly object life-time handling for XS modules
by BrowserUk (Patriarch) on Nov 06, 2017 at 13:45 UTC | |
|
Re: Multi-thread friendly object life-time handling for XS modules
by Anonymous Monk on Nov 06, 2017 at 10:30 UTC | |
by salva (Canon) on Nov 06, 2017 at 11:59 UTC | |
|
Re: Multi-thread friendly object life-time handling for XS modules
by Anonymous Monk on Nov 06, 2017 at 19:39 UTC | |
|
Re: Multi-thread friendly object life-time handling for XS modules
by Anonymous Monk on Nov 09, 2017 at 01:35 UTC | |
by salva (Canon) on Nov 09, 2017 at 20:37 UTC |