⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pth.pod

📁 Linux下的中文输入法
💻 POD
📖 第 1 页 / 共 5 页
字号:
####  GNU Pth - The GNU Portable Threads##  Copyright (c) 1999-2004 Ralf S. Engelschall <rse@engelschall.com>####  This file is part of GNU Pth, a non-preemptive thread scheduling##  library which can be found at http://www.gnu.org/software/pth/.####  This library is free software; you can redistribute it and/or##  modify it under the terms of the GNU Lesser General Public##  License as published by the Free Software Foundation; either##  version 2.1 of the License, or (at your option) any later version.####  This library is distributed in the hope that it will be useful,##  but WITHOUT ANY WARRANTY; without even the implied warranty of##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU##  Lesser General Public License for more details.####  You should have received a copy of the GNU Lesser General Public##  License along with this library; if not, write to the Free Software##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307##  USA, or contact Ralf S. Engelschall <rse@engelschall.com>.####  pth.pod: Pth manual page###                            ``Real programmers don't document.#                              Documentation is for wimps who can't#                              read the listings of the object deck.''=pod=head1 NAMEB<pth> - GNU Portable Threads=head1 VERSIONGNU Pth PTH_VERSION_STR=head1 SYNOPSIS=over 4=item B<Global Library Management>pth_init,pth_kill,pth_ctrl,pth_version.=item B<Thread Attribute Handling>pth_attr_of,pth_attr_new,pth_attr_init,pth_attr_set,pth_attr_get,pth_attr_destroy.=item B<Thread Control>pth_spawn,pth_once,pth_self,pth_suspend,pth_resume,pth_yield,pth_nap,pth_wait,pth_cancel,pth_abort,pth_raise,pth_join,pth_exit.=item B<Utilities>pth_fdmode,pth_time,pth_timeout,pth_sfiodisc.=item B<Cancellation Management>pth_cancel_point,pth_cancel_state.=item B<Event Handling>pth_event,pth_event_typeof,pth_event_extract,pth_event_concat,pth_event_isolate,pth_event_walk,pth_event_status,pth_event_free.=item B<Key-Based Storage>pth_key_create,pth_key_delete,pth_key_setdata,pth_key_getdata.=item B<Message Port Communication>pth_msgport_create,pth_msgport_destroy,pth_msgport_find,pth_msgport_pending,pth_msgport_put,pth_msgport_get,pth_msgport_reply.=item B<Thread Cleanups>pth_cleanup_push,pth_cleanup_pop.=item B<Process Forking>pth_atfork_push,pth_atfork_pop,pth_fork.=item B<Synchronization>pth_mutex_init,pth_mutex_acquire,pth_mutex_release,pth_rwlock_init,pth_rwlock_acquire,pth_rwlock_release,pth_cond_init,pth_cond_await,pth_cond_notify,pth_barrier_init,pth_barrier_reach.=item B<User-Space Context>pth_uctx_create,pth_uctx_make,pth_uctx_switch,pth_uctx_destroy.=item B<Generalized POSIX Replacement API>pth_sigwait_ev,pth_accept_ev,pth_connect_ev,pth_select_ev,pth_poll_ev,pth_read_ev,pth_readv_ev,pth_write_ev,pth_writev_ev,pth_recv_ev,pth_recvfrom_ev,pth_send_ev,pth_sendto_ev.=item B<Standard POSIX Replacement API>pth_nanosleep,pth_usleep,pth_sleep,pth_waitpid,pth_system,pth_sigmask,pth_sigwait,pth_accept,pth_connect,pth_select,pth_pselect,pth_poll,pth_read,pth_readv,pth_write,pth_writev,pth_pread,pth_pwrite,pth_recv,pth_recvfrom,pth_send,pth_sendto.=back=head1 DESCRIPTION  ____  _   _ |  _ \| |_| |__ | |_) | __| '_ \         ``Only those who attempt |  __/| |_| | | |          the absurd can achieve |_|    \__|_| |_|          the impossible.''B<Pth> is a very portable POSIX/ANSI-C based library for Unix platforms whichprovides non-preemptive priority-based scheduling for multiple threads ofexecution (aka `multithreading') inside event-driven applications. All threadsrun in the same address space of the application process, but each thread hasits own individual program counter, run-time stack, signal mask and C<errno>variable.The thread scheduling itself is done in a cooperative way, i.e., the threadsare managed and dispatched by a priority- and event-driven non-preemptivescheduler. The intention is that this way both better portability and run-timeperformance is achieved than with preemptive scheduling. The event facilityallows threads to wait until various types of internal and external eventsoccur, including pending I/O on file descriptors, asynchronous signals,elapsed timers, pending I/O on message ports, thread and process termination,and even results of customized callback functions.B<Pth> also provides an optional emulation API for POSIX.1c threads(`Pthreads') which can be used for backward compatibility to existingmultithreaded applications. See B<Pth>'s pthread(3) manual page fordetails.=head2 Threading BackgroundWhen programming event-driven applications, usually servers, lots ofregular jobs and one-shot requests have to be processed in parallel.To efficiently simulate this parallel processing on uniprocessormachines, we use `multitasking' -- that is, we have the applicationask the operating system to spawn multiple instances of itself. OnUnix, typically the kernel implements multitasking in a preemptive andpriority-based way through heavy-weight processes spawned with fork(2).These processes usually do I<not> share a common address space. Insteadthey are clearly separated from each other, and are created by directcloning a process address space (although modern kernels use memorysegment mapping and copy-on-write semantics to avoid unnecessary copyingof physical memory).The drawbacks are obvious: Sharing data between the processes iscomplicated, and can usually only be done efficiently through sharedmemory (but which itself is not very portable). Synchronization iscomplicated because of the preemptive nature of the Unix scheduler(one has to use I<atomic> locks, etc). The machine's resources can beexhausted very quickly when the server application has to serve too manylong-running requests (heavy-weight processes cost memory). And wheneach request spawns a sub-process to handle it, the server performanceand responsiveness is horrible (heavy-weight processes cost time tospawn). Finally, the server application doesn't scale very well with theload because of these resource problems. In practice, lots of tricksare usually used to overcome these problems - ranging from pre-forkedsub-process pools to semi-serialized processing, etc.One of the most elegant ways to solve these resource- and data-sharingproblems is to have multiple I<light-weight> threads of executioninside a single (heavy-weight) process, i.e., to use I<multithreading>.Those I<threads> usually improve responsiveness and performance of theapplication, often improve and simplify the internal program structure,and most important, require less system resources than heavy-weightprocesses. Threads are neither the optimal run-time facility for alltypes of applications, nor can all applications benefit from them. Butat least event-driven server applications usually benefit greatly fromusing threads.=head2 The World of ThreadingEven though lots of documents exists which describe and define the worldof threading, to understand B<Pth>, you need only basic knowledge aboutthreading. The following definitions of thread-related terms should atleast help you understand thread programming enough to allow you to useB<Pth>.=over 2=item B<o> B<process> vs. B<thread>A process on Unix systems consists of at least the following fundamentalingredients: I<virtual memory table>, I<program code>, I<programcounter>, I<heap memory>, I<stack memory>, I<stack pointer>, I<filedescriptor set>, I<signal table>. On every process switch, the kernelsaves and restores these ingredients for the individual processes. Onthe other hand, a thread consists of only a private program counter,stack memory, stack pointer and signal table. All other ingredients, inparticular the virtual memory, it shares with the other threads of thesame process.=item B<o> B<kernel-space> vs. B<user-space> threadingThreads on a Unix platform traditionally can be implemented eitherinside kernel-space or user-space. When threads are implemented by thekernel, the thread context switches are performed by the kernel withoutthe application's knowledge. Similarly, when threads are implemented inuser-space, the thread context switches are performed by an applicationlibrary, without the kernel's knowledge. There also are hybrid threadingapproaches where, typically, a user-space library binds one or moreuser-space threads to one or more kernel-space threads (there usuallycalled light-weight processes - or in short LWPs).User-space threads are usually more portable and can perform fasterand cheaper context switches (for instance via swapcontext(2) orsetjmp(3)/longjmp(3)) than kernel based threads. On the other hand,kernel-space threads can take advantage of multiprocessor machines anddon't have any inherent I/O blocking problems. Kernel-space threads areusually scheduled in preemptive way side-by-side with the underlyingprocesses. User-space threads on the other hand use either preemptive ornon-preemptive scheduling.=item B<o> B<preemptive> vs. B<non-preemptive> thread schedulingIn preemptive scheduling, the scheduler lets a thread execute until ablocking situation occurs (usually a function call which would block)or the assigned timeslice elapses. Then it detracts control from thethread without a chance for the thread to object. This is usuallyrealized by interrupting the thread through a hardware interrupt

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -