Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Let me start by saying that this post is about fixing the bug in Net::SSH2 explained here and here.

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?


In reply to Multi-thread friendly object life-time handling for XS modules by salva

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-18 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found