flockfile(3c) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

flockfile(3c)

Standard C Library Functions                                     flockfile(3C)



NAME
       flockfile, funlockfile, ftrylockfile - acquire and release stream lock

SYNOPSIS
       #include <stdio.h>

       void flockfile(FILE *stream);


       void funlockfile(FILE *stream);


       int ftrylockfile(FILE *stream);

DESCRIPTION
       The  flockfile() function acquires an internal lock of a stream stream.
       If the lock is already acquired by another thread, the  thread  calling
       flockfile()  is  suspended  until  it can acquire the lock. In the case
       that the stream lock is available, flockfile() not  only  acquires  the
       lock,  but keeps track of the number of times it is being called by the
       current thread. This implies that the stream lock can be acquired  more
       than once by the same thread.


       The  funlockfile() function releases the lock being held by the current
       thread. In the case of recursive locking, this function must be  called
       the  same  number  of times flockfile() was called. After the number of
       funlockfile() calls is equal to the number of  flockfile()  calls,  the
       stream lock is available for other threads to acquire.


       The  ftrylockfile()  function  acquires  an  internal  lock of a stream
       stream, only if that object is available. In essence ftrylockfile()  is
       a non-blocking version of flockfile().

RETURN VALUES
       The  ftrylockfile() function returns 0 on success and non-zero to indi‐
       cate a lock cannot be acquired.

EXAMPLES
       Example 1 A sample program of flockfile().




       The following example prints everything out  together,  blocking  other
       threads  that  might  want  to  write to the same file between calls to
       fprintf(3C):


         FILE iop;
         flockfile(iop);
         fprintf(iop, "hello ");
         fprintf(iop, "world);
         fputc(iop, 'a');
         funlockfile(iop);




       An unlocked interface is available in case performance is an issue. For
       example:


         flockfile(iop);
         while (!feof(iop)) {
                 *c++ = getc_unlocked(iop);
         }
         funlockfile(iop);


ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:


       tab()  box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
       TRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelMT-Safe _  Stan‐
       dardSee standards(7).


SEE ALSO
       getc(3C),   __fsetlocking(3C),   ferror(3C),   fprintf(3C),   putc(3C),
       stdio(3C), ungetc(3C), intro(3), attributes(7), standards(7)

NOTES
       The interfaces on this page are as specified in IEEE  Std  1003.1:2001.
       See standards(7).



Oracle Solaris 11.4               10 Sep 2003                    flockfile(3C)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3