in reply to Re^3: Passing globs between threads
in thread Passing globs between threads
Yes it's easy to synchronize objects (at least Storable ones) across threads. RFC677 (yes the one from IETF) tells you how.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Passing globs between threads
by BrowserUk (Patriarch) on Oct 01, 2004 at 22:22 UTC | |
Yes it's easy to synchronize objects (at least Storable ones) across threads. RFC677 (yes the one from IETF) tells you how Sorry, but I completely disagree. What RFC 677 says is that "...the problem of maintaining duplicated databases in an ARPA-like network...." is possible; Not easy! However, databases store data. In some cases code in the form of stored procedures. There is a world of difference between this and a perl object. The main one being that stored procedure code only has access to data stored with it in the DB, and constants. Perl object methods can have access to data that exists outside of the object--through references; lvalue refs; lvalue subroutines; coderefs; closures; global variables; and probably others that I haven't thought of. Perl code (methods) can also be created, modified, deleted and overridden through introspection. Stored procedures cannot. When you create an object using bless you tie (in the non-Perl sense of the word) the data (attributes) of that instance to a specific vtable of methods that exists within that same thread. When you duplicate this instance through freeze/thaw, the duplicated data is tied to a duplicate vtable. Whilst applying appropriate sharing (semaphores) and deploying appropriate locks can allow you to coordinate changes to the data across threads. Applying the same coordination to changes to the vtable is fraught with problems if not impossible. Then there is the problem of class data. Re-creating an instance of a class, does not re-create the class environment for that instance. That is to say, any class data that the instance methods might refer to--eg. Inside-out object hashes--just isn't referenceable nor duplicable. How would you coordinate an iterator returned by a method that used used closures to track state? This is a far from exhaustive rebuttal. Far, far, far...from exhaustive. However, perhaps I am missing the solution, so here's my reply: If it is so easy, show me the code. Show me the modifications required by this simple code to allow me to share an instance of Chipper such that I can pass a copy of an iterator to two threads and have them concurrently process chars from the string in a coordinated manner?
| [reply] [d/l] [select] |
by Anonymous Monk on Oct 02, 2004 at 00:27 UTC | |
But I can give an outline: Of course all data referenced by data in the "Database" must be replicated themselves and stored in the "Database". You see that I can't modify your example, because I had to write a module for the RFC677-Algorithm. | [reply] |
by BrowserUk (Patriarch) on Oct 02, 2004 at 04:56 UTC | |
Update: I think I know what I (and AnonymousMonk?) were missing. It is this section of the RFC: Note that value modification is limited to assignment. Functional modification requests - such as "Change X to be Factorial(X)" - are specifically ruled out. Allowing them would force the use of system wide synchronization interlocks. What this means (if I interpret it correctly) is that the database only stores values and retrieves them. Any new value applied is simple a new value, it can have no relationship to the previous value! Which makes it totally inapplicable for the purpose of sharing objects between threads. Your right, I didn't read it thoroughly, just scanned it a couple of times. Like most RFCs, I find the language chosen--probably for very real reasons of avoiding associations with any particular programming language, OS or other pre-existing system--makes for extremely tedious and difficult reading. However, given your precis, I have given it another read and ... well, I still not convinced. Certainly not as a realistic mechanism for object sharing in Perl(5?). I'll try to outline why. Two threads have access to a single shared scalar X. Each thread needs to increment X by 1. The sequence of operations required by each thread to do this is: Now look at (one of) the different sequences in which these action can occur on two sequentially run, pre-emptive threads. At the start of the following assume that both threads copies of the DB are synchronised and contain one selector X with a value of 2. The action to be performed by both threads is to increment the shared variable X by 1.
At point !!!Bang!!!, both threads think they have incremented X, but both threads have a value for 3 for X? Maybe I'm being thick tonight (always?), but I don't read anything explicit or implied in the RFC that deals with this overlap? Even if I am missing something, and the RFC does deal with this (which I think it must but I don't see how?), then if every simple increment or decrement of a shared value is going to require the (minimum) 7 steps I've outlined above (skiping over that:
if this was implemented, I think that the phrase that comes to mind to describe it is "slow as molasses". I know I missing something vital here--but what? | [reply] [d/l] |
by Anonymous Monk on Oct 08, 2004 at 17:19 UTC | |
by BrowserUk (Patriarch) on Oct 08, 2004 at 22:22 UTC | |
| |