1 Oct 2002 09:51
Re: Re: Kinds of threads
Alessandro Baretta <alex <at> baretta.com>
2002-10-01 07:51:08 GMT
2002-10-01 07:51:08 GMT
Michaël Grünewald wrote: > Alessandro Baretta <alex <at> baretta.com> writes: > > >>The docs say that there are two kinds of threads in O'Caml: Ocaml >>bytecode threads and POSIX threads, and that it is possible to select >>which implementation to use at compiler build time. Two questions: >>first, what is the implementation chosen in the ocaml RPM distribution; >>second, why must one choose one implementation at compiler build time? >>Why not use a compiler switch such as --posix-threads as opposed to >>--caml-threads? > > > Depending of the platform, POSIX threads may not or badly > available. Emulation can be set up, either by coercing existing thread > capabilities to the POSIX interface, or by implementing a POSIX thread > library, using processes and interprocesses communications to do the job (i > have been told it was the way with linux, please confirm or infirm it). I don't really know what you mean by "emulation", but, yes, LinuxThreads is POSIX-compliant extension to glibc which instantiates kernel-level processes. > Maybe the switch is here because it is better to use POSIX threads when they > are well supported by the system (e.g. BSDs); but the caml thread emulation > may give better results in (some) other cases. Caml threads are probably the only way to go on Windows, since the Win32 API is not POSIX compliant.(Continue reading)
Another reason is that, unlike records statically declared with
"float" fields only, tuples can be used polymorphically: a float *
float can be passed to a function expecting an 'a * 'b. This would
require run-time tests in polymorphic functions operating over tuples.
Similar tests are already generated for polymorphic functions
operating on arrays, but the tests for tuples would be more complex
because tuples, unlike arrays, are not homogeneous: one run-time test
on one component doesn't suffice to determine the type of all other
components.
> The only reason I ask is that the unboxed rep is more efficient, and tuples
> are more convenient for some things, like breaking things out with patterns:
> [...]
> or with a record
> let {x=x;y=y;z=z;} = v in
> (* need the module name on the field above if not opened, etc. *)
This is true. Despite this, I still recommend the use of records,
even if they are syntactically a bit heavier than tuples: you get the
"dot notation" (e.g. v.x, v.y, v.z in your example above), and finer
type distinctions if you need them (e.g. you might want to have
RSS Feed