Unison Help

- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
1.1.1.pthread_create() #
NAME
pthread_create – thread creation
SYNOPSIS
#include <pthread.h>
- int pthread_create(pthread_t *new_thread_ID,
- const pthread_attr_t *attr,
- void * (*start_func )(void *),
- void *arg );
DESCRIPTION
Thread creation adds a new thread of control to the system.
A newly created thread shares global data with the other threads on the same node; however, it has its own set of attributes and private execution stack. The new thread inherits the calling thread’s scheduling priority. Pending signals for a new thread are not inherited and will be empty.
The call to pthread_create() takes the address of a user-defined function, specified by start_func, which is the complete execution routine for the new thread. The new thread begins by calling the function start_func with one argument, arg . If more than one argument needs to be passed to start_func , the arguments can be packed into a structure, and the address of that structure can be passed to arg .
The start_func must never return. The results of returning from start_func are processor dependant and undefined. The routine pthread_exit() should be called to terminate a thread.
If the thread creation itself fails, a new thread is not created and the contents of the location referenced by the pointer to the new thread are undefined.
Attributes
The configuration of a set of attributes defines the behavior of a thread. At creation, each attribute of a new thread may be user-defined or set to the default. All attributes are defined upon thread creation, however, some may be dynamically modified after creation.
The available attributes are:
Attribute | Description |
stackaddr | Sets a pointer to the thread’s stack |
stacksize | Sets the size of the thread’s stack |
priority | Sets ranking within the policy (scheduling class) |
policy | Ignored |
pthread_create() creates a new thread with attributes defined by attr . Default attributes are used if attr is NULL. If any attributes specified by attr are changed in the attribute object prior to the call to pthread_create() , the new thread will acquire those changes. However, if any attributes specified by attr are changed after the call to pthread_create() , the attributes of existing threads will not be affected. Since pthread_create() can use an attribute object in its call, a user-defined thread creation must be preceded by a user-defined attribute object (see pthread_attr_init() ). Upon successful completion, and if the return value is not NULL, pthread_create() will store the ID of the created thread in the location referenced by new_thread_ID .
For the default creation attributes for pthread_create() , see pthread_attr_init().
Default thread creation:
pthread_t tid; void *start_func(void *); pthread_create(&tid, 0, start_func, 0);
This would have the same effect as:
pthread_attr_t attr; pthread_attr_init(&attr); pthread_create(&tid, &attr, start_func, 0);
To customize the attributes for POSIX threads, see pthread_attr_init().
A new thread created with pthread_create() uses the stack specified by the stackaddr attribute, and the stack continues for the number of bytes specified by the stacksize attribute.
GLOBALS
Several global variables affect thread creation. If pthreadStackFill is set, on thread creation the new threads stack is fills the stack with ‘S’ characters. Calls to pthread_stackinfo() can use this information to provide a high water mark for thread stack usage. By default pthreadStackFill is off.
The POSIX define PTHREAD_STACK_MIN points to the global variable pthreadStackMin. This defines the minimum stack size for the given processor.
If the stacksize attribute is zero, the variable pthreadStackDefault is used for the default stack size.
RETURN VALUES
Zero indicates a successful return and a non-zero value indicates an error.
ERRORS
If any of the following conditions are detected, pthread_create() fails and returns the corresponding value:
- EINVAL
- stack_base attribute is not NULL and stack_size attribute is less than PTHREAD_STACK_MIN.
- EINVAL
- stack_base attribute is NULL and stack_size attribute is not zero and is less than PTHREAD_STACK_MIN.
- EINVAL
- priority attribute is greater than PTHREAD_MAX_PRIORITY.
- ENOMEM
- Not enough memory was available to create the new thread.