· 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
The attacker must vanquish; the defender need only survive.


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.0061 sec