Loading multiple copies of a shared library

By : Demi
Source: Stackoverflow.com
Question!

I would like to be able to load multiple copies of a shared library into the same address space. I want them to not share any global variables, and I want the two copies to be unaware that the other has been loaded.

The use-case is parallel execution of a thread-unsafe library.

How can I do this

  • on Linux?
  • on OS X?
  • on Windows?
  • on *BSD?
  • on other Unix-like systems?
By : Demi


Answers

The use-case is parallel execution of a thread-unsafe library.

Even if you manage to achieve the "not share any global variables" goal (which is hard), the library may still not work, because it could be calling into thread-unsafe routines in other libraries.

The obvious case is for the library to call strtok.

On Linux and Solaris, you could use dlmopen(LM_ID_NEWLM, ...). Man page.



Your <App/> needs to handle the event. You can pass a callback function as a prop to <Menu />, on a click this function is called in App. Now the App can react to the click and pass a prop to <Canvas/>.

class App extends Component {
  constructor() {
    super();
    this.state = {clicked: false};
  }

  handleClick() {
    this.setState({clicked: !this.state.clicked});
  }

  render() {
    return (
     <div>
       <OffCanvas isClicked={this.state.clicked} />
       <Menu onClick={() => this.handleClick()} />
     </div>
    );
  }
}

This is a pretty common pattern in react.

Sidenote regarding your jquery example: All you are doing in there can easily be done with "vanilla" JS, no need for jquery.

By : Scarysize


This video can help you solving your question :)
By: admin