Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pthread_once(3) [netbsd man page]

PTHREAD_ONCE(3) 					   BSD Library Functions Manual 					   PTHREAD_ONCE(3)

NAME
pthread_once -- dynamic package initialization LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); pthread_once_t once_control = PTHREAD_ONCE_INIT; DESCRIPTION
The first call to pthread_once() by any thread in a process, with a given once_control, will call the init_routine() with no arguments. Sub- sequent calls to pthread_once() with the same once_control will not call the init_routine(). On return from pthread_once(), it is guaranteed that init_routine() has completed. The once_control parameter is used to determine whether the associated initialization routine has been called. The function pthread_once() is not a cancellation point. However, if init_routine() is a cancellation point and is cancelled, the effect on once_control is as if pthread_once() was never called. The constant PTHREAD_ONCE_INIT initializes the static once synchronization control structure once_control to be used with pthread_once(). The behavior of pthread_once() is undefined if once_control has automatic storage duration or is not initialized by PTHREAD_ONCE_INIT. RETURN VALUES
If successful, the pthread_once() function will return zero. Otherwise an error number will be returned to indicate the error. ERRORS
None. STANDARDS
The function conforms to IEEE Std 1003.1-2001 (``POSIX.1''). BSD
July 9, 2010 BSD

Check Out this Related Man Page

pthread_once(3C)														  pthread_once(3C)

NAME
pthread_once - initialize dynamic package SYNOPSIS
cc -mt [ flag... ] file... -lpthread [ library... ] #include <pthread.h> pthread_once_t once_control = PTHREAD_ONCE_INIT; int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); If any thread in a process with a once_control parameter makes a call to pthread_once(), the first call will summon the init_routine(), but subsequent calls will not. The once_control parameter determines whether the associated initialization routine has been called. The init_routine() is complete upon return of pthread_once(). pthread_once() is not a cancellation point; however, if the function init_routine() is a cancellation point and is canceled, the effect on once_control is the same as if pthread_once() had never been called. The constant PTHREAD_ONCE_INIT is defined in the <pthread.h> header. If once_control has automatic storage duration or is not initialized by PTHREAD_ONCE_INIT, the behavior of pthread_once() is undefined. Upon successful completion, pthread_once() returns 0. Otherwise, an error number is returned to indicate the error. EINVAL once_control or init_routine is NULL. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ attributes(5), standards(5) Solaris threads do not offer this functionality. 23 Mar 2005 pthread_once(3C)
Man Page

5 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Profiling..entry for a function in pthread_create

Hello, i am try to write a profiler for a multithreaded applciation. When i creat e a thread for "function f2()" the profiling information for this function does not get captured in the struct profileManager. i;e i get the exit information for "function f2()" in that thread, but the entry... (2 Replies)
Discussion started by: Vikky Panchal
2 Replies

2. AIX

valgrind - pthread memory leaks on AIX

Hi all, I have written a small code just to invoke main and return immediately. When built with libpthread on AIX box, valgrind throws lots of memory leak errors. But when built without libpthread, no issues at all. Here is the sample run for your look. Any idea where I might be going wrong?... (3 Replies)
Discussion started by: visionofarun
3 Replies

3. Programming

Linking problem

Hi! We recently updated the server (server is a big word, it's really just a desktop with Ubuntu that we access with ssh) on which we compile our code. Since the update my code won't compile. The linker is complaining about missing references from almost all .so that I'm linking from. It... (0 Replies)
Discussion started by: philippevk
0 Replies

4. Programming

pthread locking and unlocking.

When more than one thread is waiting for a locked mutex, which thread will be granted the lock first after it is released. In our application we want to implement FIFO thread scheduling policy i.e. Thread should get lock which one requested first for it. AIX have SCHED_FIFO thread scheduling... (1 Reply)
Discussion started by: mukind
1 Replies

5. Programming

C++ singleton

How to write a class that can only be instancialized once? what about my implementation below? #include<iostream> #include<stdexcept> using namespace std; class Singleton { public: int b; Singleton(); private: static int num; }; int Singleton::num = 1; (10 Replies)
Discussion started by: vistastar
10 Replies