get.datamanager <- function(x,where, how=NULL, priority=DefaultPriority) {
    # where is assumed to be an object of class DataManager
   getLock(where@tableLock)
     if(match(x, names(where@table))) {
       ans = where@table[[x]]
       yieldLock(where@tableLock)
       return(ans)
     }
      # give up the lock on the table
   yieldLock(where@tableLock)


        # problem here - can't give up that lock!
        # check in pending
   getLock(where@pendingLock)
   if(match(x, names(where@pending))) {
        # give up the lock if getLock(,condition=)
        # doesn't do the correct thing if we already hold the lock!
      thr = where@pending[[x]]
      thr.setPriority(priority)

##	yieldLock(where@pendingLock)
##	  getLock(where@pendingLock, !match(x,names(where@pending)))
##	  # we return from getLock holding the lock
##	yieldLock(where@pendingLock)

    getLock(where@tableLock,
              condition=Quote(match(x, names(where@table))))
       ans = where@table[[x]]
       yieldLock(where@tableLock)
       return(ans)
   }

       # otherwise, go create the object
   getLock(where@pendingLock)
      # make sure others now about the thread pending
      # If we grab the lock after the thread is created,
      # there is a chance that the thread may terminate
      # and also that another call may spawn a new thread
      # to create the same object
    thrd =  thread(how)
    where@pending[[x]] = thrd
   yieldLock(where@pendingLock)

    ans = join(thrd)

   getLock(where@pendingLock)
      # remove the item from pending
      # notify people waiting on where@pending?
    where@pending = where@pending[[]]
   yieldLock(where@pendingLock)


   return(ans)
 }

Duncan Temple Lang<duncan@stat.Berkeley.EDU>
Last modified: Tue Feb 25 20:30:21 1997