diff6-10.chapter24.txt

このページは最後に更新されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

last mod. 2008-08-28 (木) 09:58:03

diff6-10

13,48c13,14
<      Unix: 
<                 Programs that use the threads library must be linked as
<                follows: 
<                <<
<                          ocamlc -thread other options threads.cma other files
<                >>
<                 The -thread option selects a special, thread-safe version of
<                the standard library (see chapter 8). The -thread option must
<                also be given when compiling any source file that references
<                modules from the thread library (Thread, Mutex, ...).
<                The default thread implementation cannot be used in native-code
<                programs compiled with ocamlopt. If your operating system
<                provides POSIX 1003.1c compliant threads, you can select an
<                alternate implementation when configuring Objective Caml (use
<                the -with-pthread option to configure) which also supports
<                native-code programs. Programs that use this alternate
<                implementation of the threads library must be linked as follows:
<                
<                <<
<                          ocamlc -thread other options threads.cma other files
<                          ocamlopt -thread other options threads.cmxa other
<                files
<                >>
<                 Depending on the operating system, extra system libraries can
<                be necessary. For instance, under Solaris 2.5, add -cclib
<                -lposix4 at the end of the command line. 
<   
<      Windows: 
<                 Programs that use the threads library must be linked as
<                follows: 
<                <<
<                          ocamlc -thread other options threads.cma other files
<                >>
<                 All object files on the command line must also have been
<                compiled with the -thread option, which selects a special,
<                thread-safe version of the standard library (see chapter 8). 
---
>   Two implementations of the threads library are available, depending on the
> capabilities of the operating system: 
49a16,37
>  - System threads. This implementation builds on the OS-provided threads
>    facilities: POSIX 1003.1c threads for Unix, and Win32 threads for Windows.
>    When available, system threads support both bytecode and native-code
>    programs. 
>  - VM-level threads. This implementation performs time-sharing and context
>    switching at the level of the OCaml virtual machine (bytecode interpreter).
>    It is available on Unix systems, and supports only bytecode programs. It
>    cannot be used with native-code programs. 
>    Programs that use system threads must be linked as follows: 
> <<
>           ocamlc -thread other options unix.cma threads.cma other files
>           ocamlopt -thread other options unix.cmxa threads.cmxa other files
> >>
>    Compilation units that use the threads library must also be compiled with
> the -thread option (see chapter 8).
>   Programs that use VM-level threads must be compiled with the -vmthread option
> to ocamlc (see chapter 8), and be linked as follows: 
> <<
>           ocamlc -vmthread other options threads.cma other files
> >>
>    Compilation units that use threads library must also be compiled with the
> -vmthread option (see chapter 8).
58d45
<    
70d56
<    
75,86c61,69
<                 Thread.create funct arg creates a new thread of control,  in
<                which the function application funct arg  is executed
<                concurrently with the other threads of the program.  The
<                application of Thread.create  returns the handle of the newly
<                created thread.  The new thread terminates when the application
<                funct arg  returns, either normally or by raising an uncaught
<                exception.  In the latter case, the exception is printed on
<                standard error,  but not propagated back to the parent thread.
<                Similarly, the  result of the application funct arg is discarded
<                and not  directly accessible to the parent thread.
<   
<    
---
>     Thread.create funct arg creates a new thread of control, in which the
>    function application funct arg is executed concurrently with the other
>    threads of the program. The application of Thread.create returns the handle
>    of the newly created thread. The new thread terminates when the application
>    funct arg returns, either normally or by raising an uncaught exception. In
>    the latter case, the exception is printed on standard error, but not
>    propagated back to the parent thread. Similarly, the result of the
>    application funct arg is discarded and not directly accessible to the parent
>    thread.
94,95d76
<    
<    
100,104c81,83
<                 Return the identifier of the given thread. A thread identifier 
<                is an integer that identifies uniquely the thread.  It can be
<                used to build data structures indexed by threads.
<   
<    
---
>     Return the identifier of the given thread. A thread identifier is an
>    integer that identifies uniquely the thread. It can be used to build data
>    structures indexed by threads.
112,113d90
<    
<    
125d101
<    
130,134c106,107
<                 delay d suspends the execution of the calling thread for  d
<                seconds. The other program threads continue to run during  this
<                time.
<   
<    
---
>     delay d suspends the execution of the calling thread for d seconds. The
>    other program threads continue to run during this time.
140,143c113,114
<                 join th suspends the execution of the calling thread  until the
<                thread th has terminated.
<   
<    
---
>     join th suspends the execution of the calling thread until the thread th
>    has terminated.
151,152d121
<    
<    
159,160d127
<    
<    
167,168d133
<    
<    
173,183c138,143
<                 Suspend the execution of the calling thread until at least  one
<                character is available for reading (wait_read) or  one character
<                can be written without blocking (wait_write)  on the given Unix
<                file descriptor. Wait for at most  the amount of time given as
<                second argument (in seconds).  Return true if the file
<                descriptor is ready for input/output  and false if the timeout
<                expired. 
<                These functions return immediately true in the Win32 
<                implementation.
<   
<    
---
>     Suspend the execution of the calling thread until at least one character is
>    available for reading (wait_read) or one character can be written without
>    blocking (wait_write) on the given Unix file descriptor. Wait for at most
>    the amount of time given as second argument (in seconds). Return true if the
>    file descriptor is ready for input/output and false if the timeout expired. 
>    These functions return immediately true in the Win32 implementation.
193,198c153,156
<                 Suspend the execution of the calling thead until input/output 
<                becomes possible on the given Unix file descriptors.  The
<                arguments and results have the same meaning as for  Unix.select.
<                 This function is not implemented yet under Win32.
<   
<    
---
>     Suspend the execution of the calling thead until input/output becomes
>    possible on the given Unix file descriptors. The arguments and results have
>    the same meaning as for Unix.select. This function is not implemented yet
>    under Win32.
204,209c162,165
<                 wait_pid p suspends the execution of the calling thread  until
<                the process specified by the process identifier p  terminates.
<                Returns the pid of the child caught and  its termination status,
<                as per Unix.wait.  This function is not implemented under MacOS.
<   
<    
---
>     wait_pid p suspends the execution of the calling thread until the process
>    specified by the process identifier p terminates. Returns the pid of the
>    child caught and its termination status, as per Unix.wait. This function is
>    not implemented under MacOS.
212c168
<   val wait_signal : int list -> int
---
>   val yield : unit -> unit
215,220c171,173
<                 wait_signal sigs suspends the execution of the calling thread 
<                until the process receives one of the signals specified in the 
<                list sigs. It then returns the number of the signal received. 
<                Signal handlers attached to the signals in sigs will not  be
<                invoked. Do not call wait_signal concurrently   from several
<                threads on the same signals.
---
>     Re-schedule the calling thread without suspending it. This function can be
>    used to give scheduling hints, telling the scheduler that now is a good time
>    to switch to other threads.
223a177,186
> Management of signals
> =====================
>   
>   Signal handling follows the POSIX thread model: signals generated by a thread
> are delivered to that thread; signals generated externally are delivered to one
> of the threads that does not block it. Each thread possesses a set of blocked
> signals, which can be modified using Thread.sigmask[24.1]. This set is
> inherited at thread creation time. Per-thread signal masks are supported only
> by the system thread library under Unix, but not under Win32, nor by the VM
> thread library.
225c188
<   val yield : unit -> unit
---
>   val sigmask : Unix.sigprocmask_command -> int list -> int list
228,230c191,200
<                 Re-schedule the calling thread without suspending it.  This
<                function can be used to give scheduling hints,  telling the
<                scheduler that now is a good time to  switch to other threads.
---
>     sigmask cmd sigs changes the set of blocked signals for the calling thread.
>    If cmd is SIG_SETMASK, blocked signals are set to those in the list sigs. If
>    cmd is SIG_BLOCK, the signals in sigs are added to the set of blocked
>    signals. If cmd is SIG_UNBLOCK, the signals in sigs are removed from the set
>    of blocked signals. sigmask returns the set of previously blocked signals
>    for the thread.
>   
> <<
>   val wait_signal : int list -> int
> >>
231a202,206
>     wait_signal sigs suspends the execution of the calling thread until the
>    process receives one of the signals specified in the list sigs. It then
>    returns the number of the signal received. Signal handlers attached to the
>    signals in sigs will not be invoked. The signals sigs are expected to be
>    blocked before calling wait_signal.
240,241c215,216
< protect shared mutable data structures against concurrent accesses.  The
< typical use is (if m is the mutex associated with the data structure  D):
---
> protect shared mutable data structures against concurrent accesses. The typical
> use is (if m is the mutex associated with the data structure D): 
252d226
<    
259,260d232
<    
<    
267,268d238
<    
<    
273,278c243,245
<                 Lock the given mutex. Only one thread can have the mutex locked
<                 at any time. A thread that attempts to lock a mutex already
<                locked  by another thread will suspend until the other thread
<                unlocks  the mutex.
<   
<    
---
>     Lock the given mutex. Only one thread can have the mutex locked at any
>    time. A thread that attempts to lock a mutex already locked by another
>    thread will suspend until the other thread unlocks the mutex.
284,289c251,253
<                 Same as Mutex.lock[24.2], but does not suspend the calling
<                thread if  the mutex is already locked: just return false
<                immediately  in that case. If the mutex is unlocked, lock it and
<                 return true.
<   
<    
---
>     Same as Mutex.lock[24.2], but does not suspend the calling thread if the
>    mutex is already locked: just return false immediately in that case. If the
>    mutex is unlocked, lock it and return true.
295,297c259,260
<                 Unlock the given mutex. Other threads suspended trying to lock 
<                the mutex will restart.
<   
---
>     Unlock the given mutex. Other threads suspended trying to lock the mutex
>    will restart.
306,310c269,272
< thread has finished doing something: the former thread ``waits'' on the 
< condition variable, the latter thread ``signals'' the condition when it  is
< done. Condition variables should always be protected by a mutex.  The typical
< use is (if D is a shared data structure, m its mutex,  and c is a condition
< variable):
---
> thread has finished doing something: the former thread "waits" on the condition
> variable, the latter thread "signals" the condition when it is done. Condition
> variables should always be protected by a mutex. The typical use is (if D is a
> shared data structure, m its mutex, and c is a condition variable): 
325d286
<    
332,333d292
<    
<    
340,341d298
<    
<    
346,351c303,306
<                 wait c m atomically unlocks the mutex m and suspends the 
<                calling process on the condition variable c. The process will 
<                restart after the condition variable c has been signalled.  The
<                mutex m is locked again before wait returns.
<   
<    
---
>     wait c m atomically unlocks the mutex m and suspends the calling process on
>    the condition variable c. The process will restart after the condition
>    variable c has been signalled. The mutex m is locked again before wait
>    returns.
357,360c312,313
<                 signal c restarts one of the processes waiting on the  
<                condition variable c.
<   
<    
---
>     signal c restarts one of the processes waiting on the  condition variable
>    c.
366,368c319
<                 broadcast c restarts all processes waiting on the   condition
<                variable c.
<   
---
>     broadcast c restarts all processes waiting on the  condition variable c.
376,380c327,330
<   This module implements synchronous inter-thread communications over 
< channels. As in John Reppy's Concurrent ML system, the communication   events
< are first-class values: they can be built and combined  independently before
< being offered for communication.
<   
---
>   This module implements synchronous inter-thread communications over channels.
> As in John Reppy's Concurrent ML system, the communication  events are
> first-class values: they can be built and combined independently before being
> offered for communication.
389,390d338
<    
<    
397,398d344
<    
<    
400c346
<   type 'a event 
---
>   type +'a event 
405,406d350
<    
<    
411,414c355,356
<                 send ch v returns the event consisting in sending the value v 
<                over the channel ch. The result value of this event is ().
<   
<    
---
>     send ch v returns the event consisting in sending the value v over the
>    channel ch. The result value of this event is ().
420,424c362,363
<                 receive ch returns the event consisting in receiving a value 
<                from the channel ch. The result value of this event is the 
<                value received.
<   
<    
---
>     receive ch returns the event consisting in receiving a value from the
>    channel ch. The result value of this event is the value received.
430,433c369,370
<                 always v returns an event that is always ready for 
<                synchronization. The result value of this event is v.
<   
<    
---
>     always v returns an event that is always ready for synchronization. The
>    result value of this event is v.
439,442c376,377
<                 choose evl returns the event that is the alternative of  all
<                the events in the list evl.
<   
<    
---
>     choose evl returns the event that is the alternative of all the events in
>    the list evl.
448,452c383,384
<                 wrap ev fn returns the event that performs the same
<                communications  as ev, then applies the post-processing function
<                fn  on the return value.
<   
<    
---
>     wrap ev fn returns the event that performs the same communications as ev,
>    then applies the post-processing function fn on the return value.
458,462c390,392
<                 wrap_abort ev fn returns the event that performs  the same
<                communications as ev, but if it is not selected  the function fn
<                is called after the synchronization.
<   
<    
---
>     wrap_abort ev fn returns the event that performs the same communications as
>    ev, but if it is not selected the function fn is called after the
>    synchronization.
468,473c398,400
<                 guard fn returns the event that, when synchronized, computes 
<                fn() and behaves as the resulting event. This allows to  compute
<                events with side-effects at the time of the synchronization 
<                operation.
<   
<    
---
>     guard fn returns the event that, when synchronized, computes fn() and
>    behaves as the resulting event. This allows to compute events with
>    side-effects at the time of the synchronization operation.
479,484c406,408
<                 ``Synchronize'' on an event: offer all the communication  
<                possibilities specified in the event to the outside world,  and
<                block until one of the communications succeed. The result  value
<                of that communication is returned.
<   
<    
---
>     "Synchronize" on an event: offer all the communication  possibilities
>    specified in the event to the outside world, and block until one of the
>    communications succeed. The result value of that communication is returned.
490,493c414,415
<                 ``Synchronize'' on an alternative of events.  select evl is
<                shorthand for sync(choose evl).
<   
<    
---
>     "Synchronize" on an alternative of events. select evl is shorthand for
>    sync(choose evl).
499,504c421,424
<                 Non-blocking version of Event.sync[24.4]: offer all the
<                communication   possibilities specified in the event to the
<                outside world,  and if one can take place immediately, perform
<                it and return  Some r where r is the result value of that
<                communication.  Otherwise, return None without blocking.
<   
---
>     Non-blocking version of Event.sync[24.4]: offer all the communication 
>    possibilities specified in the event to the outside world, and if one can
>    take place immediately, perform it and return Some r where r is the result
>    value of that communication. Otherwise, return None without blocking.
514,515c434,436
< required, but do not block all threads  in the process).Thread-compatible
< system calls.
---
> required, but do not block all threads in the process).Thread-compatible system
> calls.
>   
522d442
<    
527d446
<    
532d450
<    
537d454
<    
542d458
<    
547d462
<    
552a468
> 
556d471
<    
561d475
<    
566a481
> 
570d484
<    
577,578d490
<    
<    
583,586c495,498
<                 Behave as ThreadUnix.read[24.5] and ThreadUnix.write[24.5],
<                except that  Unix_error(ETIMEDOUT,_,_) is raised if no data is 
<                available for reading or ready for writing after d seconds.  The
<                delay d is given in the fifth argument, in seconds.
---
>     Behave as ThreadUnix.read[24.5] and ThreadUnix.write[24.5], except that
>    Unix_error(ETIMEDOUT,_,_) is raised if no data is available for reading or
>    ready for writing after d seconds. The delay d is given in the fifth
>    argument, in seconds.
593d504
<    
602a514
> 
606d517
<    
611d521
<    
616d525
<    
621d529
<    
626a535
> 
630d538
<    
635a544
> 
639d547
<    
644d551
<    
649d555
<    
654d559
<    
660d564
<    
667d570
<    
673d575
<    
680d581
<

新規 編集 添付