MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Standard C Library Functions                        doorbind(3C)



NAME
     doorbind, doorunbind - bind or unbind the  current  thread
     with the door server pool

SYNOPSIS
     cc -mt [ flag... ] file... [ library... ]
     #include 

     int doorbind(int did);


     int doorunbind(void);


DESCRIPTION
     The doorbind() function associates the current thread  with
     a  door server pool. A door server pool is a private pool of
     server threads that is available to serve  door  invocations
     associated with the door did.


     The  doorunbind()  function  breaks  the   association   of
     doorbind()  by  removing any private door pool binding that
     is associated with the current thread.


     Normally, door server threads are placed in a global pool of
     available   threads  that invocations on any door can use to
     dispatch a door invocation. A door  that  has  been  created
     with  DORPRIVATE  only  uses server threads that have been
     associated with the door by  doorbind().  It  is  therefore
     necessary  to  bind  at  least  one  server thread  to doors
     created with DORPRIVATE.


     The server thread create function, doorservercreate(),  is
     initially called by the system during a doorcreate() opera-
     tion. See doorservercreate(3C) and  doorcreate(3C).


     The current thread is added to the private  pool  of  server
     threads associated with a door during the next doorreturn()
     (that has been issued by the current thread after an associ-
     ated   doorbind()).  See  doorreturn(3C).  A server thread
     performing a  doorbind() on a door that is already bound to
     a  different  door performs an implicit doorunbind() of the
     previous door.


     If a process containing threads that have been  bound  to  a
     door calls fork(2), the threads in the child process will be
     bound to an invalid door, and any calls  to  doorreturn(3C)



SunOS 5.11          Last change: 22 Mar 2005                    1






Standard C Library Functions                        doorbind(3C)



     will result in an error.

RETURN VALUES
     Upon successful completion, a 0 is returned.  Otherwise,  -1
     is returned and errno is set to indicate the error.

ERORS
     The  doorbind() and  doorunbind() functions fail if:

     EBADF     The did argument is not a valid door.


     EBADF     The doorunbind() function was called by a  thread
               that is currently not bound.


     EINVAL    did was not created with the  DORPRIVATE  attri-
               bute.


EXAMPLES
     Example 1 Use doorbind() to create private server pools for
     two doors.


     The following example shows the use of doorbind() to create
     private  server  pools  for  two  doors, d1 and d2. Function
     mycreate() is called when a new server thread is needed; it
     creates a thread running function, myservercreate(), which
     binds itself to one of the two doors.


       #include 
       #include 
       #include 
       threadkeyt doorkey;
       int d1 = -1;
       int d2 = -1;
       condt cv;       /* statically initialized to zero */
       mutext lock;    /* statically initialized to zero */

       extern void foo(void *, char *, sizet, doordesct *, uintt);
       extern void bar(void *, char *, sizet, doordesct *, uintt);

       static void *
       myservercreate(void *arg)
       {
               /* wait for d1 & d2 to be initialized */
               mutexlock(&lock);
               while (d1 == -1  d2 == -1)
                       condwait(&cv, &lock);
               mutexunlock(&lock);



SunOS 5.11          Last change: 22 Mar 2005                    2






Standard C Library Functions                        doorbind(3C)



               if (arg == (void *)foo){
                       /* bind thread with pool associated with d1 */
                       thrsetspecific(doorkey, (void *)foo);
                       if (doorbind(d1) < 0) {
                               perror("doorbind"); exit (-1);
                       }
               } else if (arg == (void *)bar) {
                       /* bind thread with pool associated with d2 */
                       thrsetspecific(doorkey, (void *)bar);
                       if (doorbind(d2) < 0) {
                       /* bind thread to d2 thread pool */
                               perror("doorbind"); exit (-1);
                       }
               }
               pthreadsetcancelstate(PTHREADCANCELDISABLE, NUL);
               doorreturn(NUL, 0, NUL, 0);  /* Wait for door invocation */
       }

       static void
       mycreate(doorinfot *dip)
       {
               /* Pass the door identity information to create function */
               thrcreate(NUL, 0, myservercreate, (void *)dip->diproc,
                       THRBOUND  THRDETACHED, NUL);
       }

       main()
       {
               (void) doorservercreate(mycreate);
               if (thrkeycreate(&doorkey, NUL) != 0) {
                       perror("thrkeycreate");
                       exit(1);
               }
               mutexlock(&lock);
               d1 = doorcreate(foo, NUL, DORPRIVATE); /* Private pool */
               d2 = doorcreate(bar, NUL, DORPRIVATE); /* Private pool */
               condsignal(&cv);
               mutexunlock(&lock);
               while (1)
                       pause();
       }


ATRIBUTES
     See attributes(5) for descriptions of the  following  attri-
     butes:









SunOS 5.11          Last change: 22 Mar 2005                    3






Standard C Library Functions                        doorbind(3C)



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     Architecture                 all                         
    
     Availability                 SUNWcsu                     
    
     Interface Stability          Stable                      
    
     MT-Level                     Safe                        
    


SEE ALSO
     fork(2),doorcreate(3C),                    doorreturn(3C),
     doorservercreate(3C), attributes(5)







































SunOS 5.11          Last change: 22 Mar 2005                    4



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™