What libraries should I use for better OCaml Threading? -


i have asked related question before why ocaml's threading considered `not enough`?

no matter how "bad" ocaml's threading is, notice libraries can real threading.

for example, lwt

lwt offers new alternative. provides light-weight cooperative threads; ``launching'' thread fast operation, not require new stack, new process, or else. context switches fast. in fact, easy launch thread every system call. , composing cooperative threads allow write highly asynchronous programs.

also jane street's aync_core provides similar things, if right.


but quite confused. lwt or aync_core provide threading java threading?

if use them, can utilise multiple cpu?

in way, can "real threading" (just in java) in ocaml?


edit

i still confused.

let me add scenario:

i have server (16 cpu cores) , server application.

what server application are:

  • it listens requests
  • for each request, starts computational task (let's costs 2 minutes finish)
  • when each task finishes, task either return result main or send result client directly

in java, easy. create thread pool, each request, create thread in pool. thread run computational task. mature in java , can utilize 16 cpu cores. right?

so question is: can same thing in ocaml?

the example of parallelized server cite 1 of embarassingly parallel problem solved simple multiprocessing model, using fork. has been doable in ocaml decades, , yes, linear speedup using cores of machine if need.

to using simple primitives of standard library, see this chapter of online book "unix system programming in ocaml" (first released in 2003), and/or this chapter of online book "developing applications ocaml" (first released in 2000).

you may want use higher-level libraries such gerd stolpmann's ocamlnet library mentioned rafix, provides lot of stuff direct helper usual client/server design, lower-level multiprocess communication libraries; see the documentation.

the library parmap interesting, maybe different use case (it's more have large array of data available @ same time, want process same function in parallel): drop-in remplacement of array.map or list.map (or fold) parallelizes computations.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -