dark_light changed the topic of #ocaml to: OCaml 3.09.2 available! Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
hikozaemon has joined #ocaml
Frederick has joined #ocaml
Frederick has left #ocaml []
dark_light has joined #ocaml
<dark_light> how can i make a global variable that is visible by all forks?
slipstream has quit [Remote closed the connection]
slipstream has joined #ocaml
<dark_light> i noticed that after a fork all data is copied, so if i change a external value, it will not affect other forks..
<Smerdyakov> Why do you want to use fork?
<dark_light> i am using Unix.establish_server
<dark_light> i could use threads, but threads has problems with locks
<Smerdyakov> Does it have problems with using the Concurrent ML port, the Event module?
<dark_light> i don't want to use Mutex every time i change something.. i was thinking in make objects that use mutex transparently, but i am trying establish_server now
<dark_light> Smerdyakov, Event? huuum..
<dark_light> Event can store values?
<dark_light> i want a place to store global data
<Smerdyakov> You use message passing, with no shared imperative state.
<dark_light> well, it can work like a 'shared imperative state'?
<dark_light> i think if every fork copies all data, it will be slow
<dark_light> because maybe i will have huge data
<dylan> fork is very fast on Linux.
<dylan> it copies nothing it doesn't need to.
<dark_light> dylan, but i want a way to modify a "global" variable inside a fork
<dylan> from fork(2):
<dylan> " Under Linux, fork() is implemented using copy-on-write pages, so the only penalty that it incurs is the time and memory required to duplicate the
<dylan> parent's page tables, and to create a unique task structure for the child.
<dylan> "
<dark_light> if i use event, i may have to copy all data in all forks
<dylan> Either way you need to 'copy' the data.
<dark_light> if I use threads, the data would be shared
<dylan> shared mutable state is bad.
<dylan> either fork + IPC or threads + the event module is the way to go
<dark_light> ipc? unix sockets?
<dark_light> hm
<dylan> IPC -- sockets, fifos, sysv shared memory, etc.
<dylan> currently fork + sockets will be more scalable on a multiprocessor machine.
<dylan> ocaml threads cannot take advantage of multiproc systems because of a global lock on the garbage collector, I believe.
<dylan> (it's not likely to change for a long time, either, as the ocaml GC has been proven correct with coq -- if I remember correctly)
<dark_light> well.. i though it would be very simple..
<Smerdyakov> dark_light, with the CML style, "mutable" state is stored implicitly in closures.
<dark_light> cml?
<Smerdyakov> Concurrent ML
<dark_light> it's another variant of ml?
<Smerdyakov> It's a library for SML/NJ, originally.
<Smerdyakov> Like I said, the major parts are implemented in the OCaml Event module.
<dark_light> is there any way to port fork() to windows? i am thinking in use thread in part because of this
<Smerdyakov> There's one heap shared by all threads, and thread-local state is effectively encoded in each thread's current continuation.
<Smerdyakov> I don't know any reason why you would want to use fork over threads.
<dark_light> i am using forks because they come with Unix.establish_server, because i am so lazy to handle with file_descr .. looking on establish_server's code, i don't know how to use thread instead..
<Smerdyakov> CML is so much nicer. I'm sure you can reimplement any of that Unix.* functionality that you need quickly enough.
<dylan> Smerdyakov: You'd want to in ocaml for decent performance on multiprocessor or dual core machines.
<dylan> (to use fork)
<dylan> Otherwise, you get the per-thread overhead of threads and all of the time advantages of a single-threaded state machine...
<dark_light> where can i find cml? it isn't on caml hump..
<dylan> Event comes with ocaml
<dylan> (Event being a clone of CML for ocaml)
<dark_light> Ah
mattam has quit [SendQ exceeded]
ketty has quit [Read error: 113 (No route to host)]
shekmalhen has joined #ocaml
chessguy has joined #ocaml
Smerdyakov has quit ["Leaving"]
shekmalhen has quit ["Bêêêêêêêêh!"]
chessguy has quit [" Want to be different? HydraIRC -> http://www.hydrairc.com <-"]
smimou has joined #ocaml
Snark has joined #ocaml
smimou has quit [Remote closed the connection]
pango has quit [Remote closed the connection]
pango has joined #ocaml
<dark_light> the global module from extlib (http://ocaml-lib.sourceforge.net/doc/Global.html) is a good way to share information between two forked processes?
<pango> I doubt they would be shared about forked processes
<dark_light> maybe it's possible to build a Global module that shares global values transparently (maybe using event)
<pango> processes don't share their memory space, that's the main difference with threads
<pango> so you need some form of IPC
<dark_light> like Event?
<pango> they're shared memory segments, but you'll probably have to manage them by yourself
<pango> IPC = Inter Process Communication
<dark_light> how can i use ipc with ocaml?
<pango> that means sockets, pipes, shared memory segments,...
<pango> mutexes...
<dark_light> the first two is used with unix module, and the third?
<dark_light> and somebody said here that event module would be a good way to make two processes communicate with each other
<pango> thru pipes I suppose
pango is now known as pangoafk
<dark_light> how can i have a list of all processes? i can make this list inside the main process, but i will be unable to read a modification inside a son..
revision17_ has joined #ocaml
Revision17 has quit [Read error: 110 (Connection timed out)]
pangoafk is now known as pango
<pango> dark_light: that's usually not how it's done; instead you create an IPC in the main process, that's shared with children thru fork
<pango> some book on Unix programming would probably help
love-pingoo has joined #ocaml
<dark_light> hmm..
<dark_light> and, a licensing question: i have a program released under gpl. if i need a improved version of a function in standard library (that is lgpl with some exceptions) and copy and modify this function in a file that is part of the program, can i still release the program (and this file specially) as gpl? i must write in this file the function author's name?
<love-pingoo> that's what I do, but I don't know if LGPL allows you to release the modified code under GPL
<love-pingoo> anyway, if it's a small function, especially since you modify it, this shouldn't be a very critical issue
<mellum> There's always the option of, like, actually *reading* the license
<dark_light> the gnu licenses are large and my english isn't so good (actually i can't read even legal texts in portuguese, my first language.. :P), there are so much details
dark_light has quit [Remote closed the connection]
mattam has joined #ocaml
hikozaemon has quit ["Leaving..."]
dark_light has joined #ocaml
dark_light has quit [SendQ exceeded]
mnemonic has joined #ocaml
<mnemonic> hi
dark_light has joined #ocaml
<dark_light> i am with problems to pad a number with zeroes. Printf.printf "%0*d\n" 10 5;; returns "5" instead of "0000000005"
<dark_light> ops, prints 5 instead of 0000000005
<dark_light> Printf.printf "%*d\n" 10 5 works fine, but pad with spaces..
<dylan> # sprintf "%.5d" 5 ;;
<dylan> - : string = "00005"
<dark_light> thanks, but.. 00005 isn't 5 with width 5? i though precision is only for floats
<dark_light> and, well, i need a way to give the width with a variable
<dark_light> so i must use *..
<dylan> and replace ' ' with '0'?
<dylan> it seems like %.nd does just what you need, though
<dark_light> well, i am using the one with spaces and replacing to 0.. but the documentation says that if i specify 0 flag, it would pad with zeroes..
<dark_light> %.nd isn't what i need because i am doing it with a variable width
<dylan> I can observe no difference between .nd and *d, other than one takes another argument.
<dark_light> but the argument is an int
<pango> use of . for ints is not even documented...
<dark_light> with .nd i would have to do string_of_int and use ^..
<pango> that looks like a bug in printf
<dylan> . for ints is a normal feature of C's printf.
<pango> that why I wouldn't have guessed
<dylan> printf.ml doesn't seem to actually bother looking for a '0' with the width specifier.
<dark_light> in 'flags', it don't look for 0?
<dark_light> but 0: for numerical conversions, pad with zeroes instead of spaces.
dark_light has quit [Read error: 110 (Connection timed out)]
dark_light has joined #ocaml
<dark_light> can i execute a program getting a out_channel to write to its stdin (like Unix.open_process) but waiting for it terminates (like Unix.system)?
<pango> Unix.open_process_out + Unix.close_process_out ?
<dark_light> Hmmmm.. ok
<dark_light> thanks
slipstream-- has joined #ocaml
slipstream has quit [Connection reset by peer]
Smerdyakov has joined #ocaml
finelemo2 has quit [Read error: 104 (Connection reset by peer)]
mnemonic has quit ["leaving"]
finelemon has joined #ocaml
love-pingoo has quit ["Leaving"]
smimou has joined #ocaml
dark_light has quit [Remote closed the connection]
descender has quit ["Why has elegance found so little following? Elegance has the disadvantage that hard work is needed to achieve it and a good e]
pango has quit ["Leaving"]
ketty has joined #ocaml
pango has joined #ocaml
vincenz has joined #ocaml
Oxyd has joined #ocaml
Snark has quit [Read error: 110 (Connection timed out)]
Snark has joined #ocaml
Schmurtz has joined #ocaml
TeXitoi has joined #ocaml
vincenz has left #ocaml []
khaladan has joined #ocaml
shawn has quit ["This computer has gone to sleep"]
Oxyd has quit ["Vanitas vanitatum et omnia vanitas."]
ketty has quit [Remote closed the connection]
Snark has quit ["Leaving"]
TeXitoi has left #ocaml []
mnemonic has joined #ocaml
<mnemonic> re
love-pingoo has joined #ocaml
ketty has joined #ocaml
smimou has quit ["bli"]
love-pingoo has quit ["Connection reset by pear"]
mnemonic has quit ["leaving"]
Schmurtz has quit ["L'énergie semble manquer : dodo !"]