>[2nd send, the first one didn't showed up]
>
>I'm in the process of writing a "Hello-World" plugin (which already
works
>great! [well, if it wasn't, I'd be a very bad coder, heh?]) as a proof
of
>concept to extend the current plugin mechanism (and before the Bochs
plugin
>gets fragmented) and to write some sample for whoever wants to write
>plugins. Heavily commented, you can be sure :-)
>
>One of the thing I came across is the lack of support for many
instances of
>a single plugin. This requires at least a way to specify which instance
we
>are talking to, when we query or even terminate the instance
(plugin_fini).
>This is not a problem with IO/Int events, though, as the plugin can
easily
>figure it out itself.
>
>I figured out two solutions. Pointers to the plugin can be passed to
each
>concerned function, à la C++ "this" pointer, or use a Lock/Unlock
mechanism
>with mutexes to fix the plugin's internal "current instance" pointer,
and
>then call the functions.
>
Umm, won't that still affect the variables?
MyPlugin a, b;
Thread 1:
a.DoWhatever();
a.DoOtherStuff()
Thread 2.
b.DoWhatever();
MyPlugin.DoWhatever() {
acquire_mutex();
// modify variables
release_mutex();
}
MyPlugin.DoOtherStuff() {
// modify yet another variable,
// depending on the ones in DoWhatever()
}
Let's say the system decided to run your code like this:
a.DoWhatever();
b.DoWhatever();
a.DoOtherStuff();
Oops, seems like we're using the wrong values of a's variables.
Or, did I get something wrong? This is at least what you have to think
of in BeOS kernel programming; multithreaded, re-entrant kernel.
--
Mikael J @ http://hem.spray.se/tic_khr
Registered and Proud BeOS Developer