Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!bywater!scifi!paladin!beal From: beal@paladin.owego.ny.us (Alan Beal) Newsgroups: comp.unix.internals Subject: Re: shared libraries can be done right Message-ID: <675052046.101301@paladin.owego.ny.us> Date: 24 May 91 02:27:25 GMT References: <20May91.042630.9136@franklin.com> Distribution: usa Organization: The Design Committee Lines: 59 I just came into them middle of this discussion on shared libraries, and I was wondering if someone could explain the typical UNIX implementation of shared libraries. UNISYS Large Systems(A-series) have libraries(shared and private); since I understand how these work, let me explain the implementation and you might be able to explain how UNIX's implementation differs. First of all, a UNISYS library runs as a separate task; it is initiated by the OS when a program calls one its procedures. The library after beginning to run performs any initialization code and then 'freezes' which in effect makes its exported procedures available for other programs to use. The library can 'unfreeze' when noone is using its code if it froze temporarily or via the operator THAW command if it froze permanently. Essentially a library acts like a server but only is initiated when needed and may terminate when no longer in use. Here is some sample code in ALGOL: library(*SYSTEM/A) calling program ------------------------------- ---------------------------------------- BEGIN BEGIN % GLOBAL DATA INTEGER AMOUNT, NEW_A; INTEGER A; LIBRARY LIB(TITLE='*SYSTEM/A.'); INTEGER PROCEDURE INCREMENT_A(AMT); INTEGER AMT; INTEGER PROCEDURE INCREMENT_A(B); BEGIN LIBRARY LIB; INCREMENT_A := A + AMT; END; %---- OUTER BLOCK ---- AMOUNT := 2; %----- OUTER BLOCK, INITIALIZE A --- NEW_A := INCREMENT_A(AMOUNT); EXPORT INCREMENT_A; END. A := 0; FREEZE(PERMANENT) END. In my example INCREMENT_A is a shared library procedure that happens to access a global variable. When the procedure is called, the OS initiates the library, executes the procedure, and returns back to the calling program. If it is a shared library, then multiple calling programs can call the same procedure at the same time; of course you have to code for mutual exclusion of global data in the library. The name of the library (*SYSTEM/A) can be changed at run-time if desired. This is basically how the database software(*SYSTEM/ACCESSROUTINES) works for these systems. Advantages: reduced number of tasks in the system, encourages reusable code, and reduces the binary size of the calling programs. Disadvantages: library procedure calls are so-what slower and shared libraries must code for mutual exclusion. I assume UNIX shared libraries are dynamicly linked libraries with shared text and separate data. If so, then it looks like the major difference is that UNIX libraries are not separate tasks. Does any one see any advantages of one over the other? What do you think of Unisys's implementation - it has been around for awhile? -- Alan Beal Internet: beal@paladin.Owego.NY.US USENET: {uunet,uunet!bywater!scifi}!paladin!beal