· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
hey

헤이 = 해이 = 어이

사실 KLDP BBS가 너무 재밌어서 KLDP Wiki에 안 들어온지 오래 되었습니다. 죄송합니다. (_ _)

GnuPth 번역

왜 DocBook으로 작업했을까? 참여하기 어렵다.

Thread Control

The following functions control the threading itself and make up the main API of the Pth library.

  • pth_t pth_spawn(pth_attr_t attr, void *(*entry)(void *), void *arg);


    이 함수는 entry 루틴을 시작점으로 attr(이나 기본값으로 현재 쓰레드에서 물려받은 쓰레드 우선순위, Join 허용, 취소 상태를 가지는 PTH_ATTR_DEFAULT)에서 주어진 속성을 사용해 새로운 쓰레드를 생성한다. 단 dispatch 횟수는 attr이 지정되지 않아도 현 쓰레드의 값을 물려받지 않고 0으로 초기화된다. 이 entry 루틴은 새로운 쓰레드의 안쪽에서 `pth_exit(entry(arg)' 형식으로 불려진다. 즉 entry의 반환값이 pth_exit(3)에 암시적으로 주어진다. 그래서 쓰레드도 반환값을 가지고 종료될 수 있다. 그럼에도 불구하고 쓰레드는 pth_exit(3)을 불러서 언제든지 명시적으로 종료할 수도 있다. 그러나 POSIX 표준 함수 exit(3)을 부르는 것은 프로세스를 완전히 끝내긴 하지만 현재 쓰레드는 포함하지 않는다는 것을 명심해야한다.


    가상 메모리가 허용하는 한계 외에는 Pth 내부에서 지정하는 생성될 수 있는 쓰레드의 갯수 한계는 없다. Pth는 내부적으로 동적 데이터 구조에서 쓰레드의 트랙을 유지한다. 함수는 에러가 발생하면 NULL을 반환한다.


  • int pth_once(pth_once_t *ctrlvar, void (*func)(void *), void *arg);


    이것은 생성자 함수 func이 `func(arg)' 형태로 시스템에서 단 한 번만 불리도록 하기 위해 pth_once_t 형의 제어 변수를 사용하는 편리한 함수다. 다시 말하면 시스템의 어떤 쓰레드에서든 오직 첫 번째 pth_once(3)의 호출만이 성공한다. 이 함수를 부르기 전 `pth_once_t 변수이름 = PTH_ONCE_INIT;' 형태로 정의된 ctrlvar를 통해 변수가 참조된다.


  • pth_t pth_self(void);


    This just returns the unique thread handle of the currently running thread. This handle itself has to be treated as an opaque entity by the application. It's usually used as an argument to other functions who require an argument of type pth_t.


  • int pth_suspend(pth_t tid);


    This suspends a thread tid until it is manually resumed again via pth_resume(3). For this, the thread is moved to the SUSPENDED queue and this way is completely out of the scheduler's event handling and thread dispatching scope. Suspending the current thread is not allowed. The function returns TRUE on success and FALSE on errors.


  • int pth_resume(pth_t tid);


    This function resumes a previously suspended thread tid, i.e. tid has to stay on the SUSPENDED queue. The thread is moved to the NEW, READY or WAITING queue (dependent on what its state was when the pth_suspend(3) call were made) and this way again enters the event handling and thread dispatching scope of the scheduler. The function returns TRUE on success and FALSE on errors.


  • int pth_raise(pth_t tid, int sig)


    This function raises a signal for delivery to thread tid only. When one just raises a signal via raise(3) or kill(2), its delivered to an arbitrary thread which has this signal not blocked. With pth_raise(3) one can send a signal to a thread and its guarantees that only this thread gets the signal delivered. But keep in mind that nevertheless the signals action is still configured process-wide. When sig is 0 plain thread checking is performed, i.e., `pth_raise(tid, 0)' returns TRUE when thread tid still exists in the PTH system but doesn't send any signal to it.


  • int pth_yield(pth_t tid);


    This explicitly yields back the execution control to the scheduler thread. Usually the execution is implicitly transferred back to the scheduler when a thread waits for an event. But when a thread has to do larger CPU bursts, it can be reasonable to interrupt it explicitly by doing a few pth_yield(3) calls to give other threads a chance to execute, too. This obviously is the cooperating part of Pth. A thread has not to yield execution, of course. But when you want to program a server application with good response times the threads should be cooperative, i.e., when they should split their CPU bursts into smaller units with this call.


    Usually one specifies tid as NULL to indicate to the scheduler that it can freely decide which thread to dispatch next. But if one wants to indicate to the scheduler that a particular thread should be favored on the next dispatching step, one can specify this thread explicitly. This allows the usage of the old concept of coroutines where a thread/routine switches to a particular cooperating thread. If tid is not NULL and points to a new or ready thread, it is guaranteed that this thread receives execution control on the next dispatching step. If tid is in a different state (that is, not in PTH_STATE_NEW or PTH_STATE_READY) an error is reported.


    The function usually returns TRUE for success and only FALSE (with errno set to EINVAL) if tid specified an invalid or still not new or ready thread.


  • int pth_nap(pth_time_t naptime);


    This functions suspends the execution of the current thread until naptime is elapsed. naptime is of type pth_time_t and this way has theoretically a resolution of one microsecond. In practice you should neither rely on this nor that the thread is awakened exactly after naptime has elapsed. It's only guarantees that the thread will sleep at least naptime. But because of the non-preemptive nature of Pth it can last longer (when another thread kept the CPU for a long time). Additionally the resolution is dependent of the implementation of timers by the operating system and these usually have only a resolution of 10 microseconds or larger. But usually this isn't important for an application unless it tries to use this facility for real time tasks.


  • int pth_wait(pth_event_t ev);


    This is the link between the scheduler and the event facility (see below for the various pth_event_xxx() functions). It's modeled like select(2), i.e., one gives this function one or more events (in the event ring specified by ev) on which the current thread wants to wait. The scheduler awakes the thread when one ore more of them occurred or failed after tagging them as such. The ev argument is a pointer to an event ring which isn't changed except for the tagging. pth_wait(3) returns the number of occurred or failed events and the application can use pth_event_status(3) to test which events occurred or failed.


  • int pth_cancel(pth_t tid);


    This cancels a thread tid. How the cancellation is done depends on the cancellation state of tid which the thread can configure itself. When its state is PTH_CANCEL_DISABLE a cancellation request is just made pending. When it is PTH_CANCEL_ENABLE it depends on the cancellation type what is performed. When its PTH_CANCEL_DEFERRED again the cancellation request is just made pending. But when its PTH_CANCEL_ASYNCHRONOUS the thread is immediately canceled before pth_cancel(3) returns. The effect of a thread cancellation is equal to implicitly forcing the thread to call `pth_exit(PTH_CANCELED)' at one of his cancellation points. In Pth thread enter a cancellation point either explicitly via pth_cancel_point(3) or implicitly by waiting for an event.


  • int pth_abort(pth_t tid);


    This is the cruel way to cancel a thread tid. When it's already dead and waits to be joined it just joins it (via `pth_join(tid, NULL)') and this way kicks it out of the system. Else it forces the thread to be not joinable and to allow asynchronous cancellation and then cancels it via `pth_cancel(tid)'.


  • int pth_join(pth_t tid, void **value);


    This joins the current thread with the thread specified via tid. It first suspends the current thread until the tid thread has terminated. Then it is awakened and stores the value of tid's pth_exit(3) call into *value (if value and not NULL) and returns to the caller. A thread can be joined only when it has the attribute PTH_ATTR_JOINABLE set to TRUE (the default). A thread can only be joined once, i.e., after the pth_join(3) call the thread tid is completely removed from the system.


  • void pth_exit(void *value);


    This terminates the current thread. Whether it's immediately removed from the system or inserted into the dead queue of the scheduler depends on its join type which was specified at spawning time. If it has the attribute PTH_ATTR_JOINABLE set to FALSE, it's immediately removed and value is ignored. Else the thread is inserted into the dead queue and value remembered for a subsequent pth_join(3) call by another thread.

Dear hey

  • 성남사시는 분이시군요! 반갑습니다 :) - dasomoli


안녕? 테러분자 같은 우리 쏜님~ ojb1112 위키의 세계는 블로그보다 어려운것 같군 -_-;

ID
Password
Join
You will attract cultured and artistic people to your home.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2007-08-09 10:32:58
Processing time 0.0068 sec