Loading ...
Sorry, an error occurred while loading the content.
 

Re: "ocaml_beginners"::[] One simple example with Threads...

Expand Messages
  • Oliver Bandel
    ... [...] Heheh, fine. :) [...] ... Oh, well... yes, it looks like you have to use Threads then. But in the Unix-module-documentation there also is a function
    Message 1 of 29 , Nov 4, 2007
      Zitat von Fabrice Marchant <fabrice.marchant@...>:

      > On Sat, 3 Nov 2007 12:52:42 +0100
      > Oliver Bandel <oliver@...-berlin.de> wrote:
      >
      > > > I think it is a good start point for hacking. Thanks for the
      > > > explanations too.
      > > [...]
      > >
      > > For learning? -> yes.
      > > For hacking? -> yes, but the code is GPLed.
      > I never think to another license : GPL forever !
      [...]

      Heheh, fine. :)

      [...]
      > Thanks a lot, but I realize I must use threads only, if I want some of my
      > programs runs on Windoz too.

      Oh, well... yes, it looks like you have to use Threads then.

      But in the Unix-module-documentation there also is a
      function "create_process" mentioned, that can be used instead of fork.

      Maybe that is an emulation of fork by using threads?!

      Ciao,
      Oliver
    • Richard Jones
      ... Not necessarily. There exist implementations of fork , pipe etc. for Windows, most notably Cygwin. Also it s perfectly possible to write Windows
      Message 2 of 29 , Nov 4, 2007
        On Sun, Nov 04, 2007 at 01:24:10AM +0100, Fabrice Marchant wrote:
        > Thanks a lot, but I realize I must use threads only, if I want some
        > of my programs runs on Windoz too.

        Not necessarily. There exist implementations of 'fork', 'pipe' etc.
        for Windows, most notably Cygwin. Also it's perfectly possible to
        write Windows programs which listen on TCP/IP sockets, or stdin/
        stdout, just using standard OCaml functions (from the mis-named 'Unix'
        module, which mostly works on Windows).

        Rich.

        --
        Richard Jones
        Red Hat
      • Oliver Bandel
        ... [...] Why misnamed ? That s the Unix-API for OCaml. And for windows it was be ported/emulated or needs Cygwin, which is a kind of Unix-emulation. So I
        Message 3 of 29 , Nov 4, 2007
          Zitat von Richard Jones <rich@...>:

          > On Sun, Nov 04, 2007 at 01:24:10AM +0100, Fabrice Marchant wrote:
          > > Thanks a lot, but I realize I must use threads only, if I want some
          > > of my programs runs on Windoz too.
          >
          > Not necessarily. There exist implementations of 'fork', 'pipe' etc.
          > for Windows, most notably Cygwin. Also it's perfectly possible to
          > write Windows programs which listen on TCP/IP sockets, or stdin/
          > stdout, just using standard OCaml functions (from the mis-named 'Unix'
          > module, which mostly works on Windows).
          [...]

          Why "misnamed"?

          That's the Unix-API for OCaml.
          And for windows it was be ported/emulated
          or needs Cygwin, which is a kind of Unix-emulation.

          So I don't thing it is a misnomer.

          Ciao,
          Oliver
        • Richard Jones
          ... OK, fair enough point. I just think that sometimes beginners think that because the module is called Unix it only works on Unix ... I also dug up this
          Message 4 of 29 , Nov 4, 2007
            On Sun, Nov 04, 2007 at 04:03:51PM +0100, Oliver Bandel wrote:
            > Zitat von Richard Jones <rich@...>:
            >
            > > On Sun, Nov 04, 2007 at 01:24:10AM +0100, Fabrice Marchant wrote:
            > > > Thanks a lot, but I realize I must use threads only, if I want some
            > > > of my programs runs on Windoz too.
            > >
            > > Not necessarily. There exist implementations of 'fork', 'pipe' etc.
            > > for Windows, most notably Cygwin. Also it's perfectly possible to
            > > write Windows programs which listen on TCP/IP sockets, or stdin/
            > > stdout, just using standard OCaml functions (from the mis-named 'Unix'
            > > module, which mostly works on Windows).
            > [...]
            >
            > Why "misnamed"?
            >
            > That's the Unix-API for OCaml.
            > And for windows it was be ported/emulated
            > or needs Cygwin, which is a kind of Unix-emulation.
            >
            > So I don't thing it is a misnomer.

            OK, fair enough point. I just think that sometimes beginners think
            that because the module is called "Unix" it only works on Unix ...

            I also dug up this posting, Xavier on threads:

            http://caml.inria.fr/pub/ml-archives/caml-list/2002/11/64c14acb90cb14bedb2cacb73338fb15.en.html

            Rich.

            --
            Richard Jones
            Red Hat
          • Fabrice Marchant
            On Sun, 4 Nov 2007 15:13:24 +0000 ... Please does Unix and Sys module require Cygwin to work on Windows ? Does Thread too ? ... Thanks for the link,
            Message 5 of 29 , Nov 4, 2007
              On Sun, 4 Nov 2007 15:13:24 +0000
              Richard Jones <rich@...> wrote:

              > OK, fair enough point. I just think that sometimes beginners think
              > that because the module is called "Unix" it only works on Unix ...
              Please does "Unix" and "Sys" module require Cygwin to work on Windows ?
              Does "Thread" too ?

              > I also dug up this posting, Xavier on threads:
              >
              > http://caml.inria.fr/pub/ml-archives/caml-list/2002/11/64c14acb90cb14bedb2cacb73338fb15.en.html

              Thanks for the link,

              Regards,

              Fabrice
            • Fabrice Marchant
              On Sun, 4 Nov 2007 14:11:12 +0100 ... I need to discover a bit OCaml needs and behaviour on Windows. Regards, Fabrice
              Message 6 of 29 , Nov 4, 2007
                On Sun, 4 Nov 2007 14:11:12 +0100
                Oliver Bandel <oliver@...-berlin.de> wrote:

                > Zitat von Fabrice Marchant <fabrice.marchant@...>:
                >
                > > On Sat, 3 Nov 2007 12:52:42 +0100
                > > Oliver Bandel <oliver@...-berlin.de> wrote:
                > >
                > > > > I think it is a good start point for hacking. Thanks for the
                > > > > explanations too.
                > > > [...]
                > > >
                > > > For learning? -> yes.
                > > > For hacking? -> yes, but the code is GPLed.
                > > I never think to another license : GPL forever !
                > [...]
                >
                > Heheh, fine. :)
                >
                > [...]
                > > Thanks a lot, but I realize I must use threads only, if I want some of my
                > > programs runs on Windoz too.
                >
                > Oh, well... yes, it looks like you have to use Threads then.
                >
                > But in the Unix-module-documentation there also is a
                > function "create_process" mentioned, that can be used instead of fork.
                >
                > Maybe that is an emulation of fork by using threads?!

                I need to discover a bit OCaml needs and behaviour on Windows.

                Regards,

                Fabrice
              • Adrien
                ... Unix and Sys perfectly work on windows except a few things in Unix. In ocaml s source, look at the otherlibs directory ; you ll see two directories names
                Message 7 of 29 , Nov 4, 2007
                  2007/11/4, Fabrice Marchant <fabrice.marchant@...>:
                  > On Sun, 4 Nov 2007 15:13:24 +0000
                  > Richard Jones <rich@...> wrote:
                  >
                  > > OK, fair enough point. I just think that sometimes beginners think
                  > > that because the module is called "Unix" it only works on Unix ...
                  > Please does "Unix" and "Sys" module require Cygwin to work on Windows ?
                  > Does "Thread" too ?

                  Unix and Sys perfectly work on windows except a few things in Unix.
                  In ocaml's source, look at the otherlibs directory ; you'll see two
                  directories names "win32graph" and "win32unix". On windows they are
                  built instead of graph and unix.

                  I can't speak for Thread though as I never used this functionnality.


                  ---

                  Adrien Nader
                • Christophe TROESTLER
                  ... http://caml.inria.fr/pub/docs/manual-ocaml/manual035.html
                  Message 8 of 29 , Nov 4, 2007
                    On Sun, 4 Nov 2007 22:58:23 +0100, Fabrice Marchant wrote:
                    >
                    > Please does "Unix" and "Sys" module require Cygwin to work on Windows ?

                    http://caml.inria.fr/pub/docs/manual-ocaml/manual035.html
                  • Peter C. Chapin
                    ... The interface is really about POSIX, not Unix. The POSIX interface can be provided by operating systems other than Unix, such as Windows (and others).
                    Message 9 of 29 , Nov 6, 2007
                      Richard Jones wrote:

                      >> Why "misnamed"?
                      >>
                      >> That's the Unix-API for OCaml.
                      >> And for windows it was be ported/emulated
                      >> or needs Cygwin, which is a kind of Unix-emulation.
                      >>
                      >> So I don't thing it is a misnomer.
                      >
                      > OK, fair enough point. I just think that sometimes beginners think
                      > that because the module is called "Unix" it only works on Unix ...

                      The interface is really about POSIX, not Unix. The POSIX interface can
                      be provided by operating systems other than Unix, such as Windows (and
                      others). Calling the module "Unix" is exposing an implementation detail
                      that shouldn't be in the interface.

                      Peter





                      [Non-text portions of this message have been removed]
                    • Oliver Bandel
                      ... Why do you think so? Some POSIX-Standards are covering what came from Unix, and later were expanded. So, Unix-API might be a subset of POSIX-API.
                      Message 10 of 29 , Nov 6, 2007
                        Zitat von "Peter C. Chapin" <Peter.Chapin@...>:

                        > Richard Jones wrote:
                        >
                        > >> Why "misnamed"?
                        > >>
                        > >> That's the Unix-API for OCaml.
                        > >> And for windows it was be ported/emulated
                        > >> or needs Cygwin, which is a kind of Unix-emulation.
                        > >>
                        > >> So I don't thing it is a misnomer.
                        > >
                        > > OK, fair enough point. I just think that sometimes beginners think
                        > > that because the module is called "Unix" it only works on Unix ...
                        >
                        > The interface is really about POSIX, not Unix.

                        Why do you think so?

                        Some POSIX-Standards are covering what came from Unix,
                        and later were expanded.
                        So, Unix-API might be a subset of POSIX-API.
                        Nevertheless Unix-systems later used POSIX-stuff.

                        So, it's not so easy to make a distinction there.
                        That is a historical issue.

                        Where do you think is the Unix module a POSIX-module and NOT
                        a Unix-module?



                        > The POSIX interface can
                        > be provided by operating systems other than Unix,

                        Yes.


                        > such as Windows (and
                        > others).

                        What's about fork and similar functions, that are available on Unix,
                        but not on Windows?
                        Isn't fork a part of POSIX-standards also?
                        But it's available on Unix only, so I would think
                        the name for that module is OK.


                        > Calling the module "Unix" is exposing an implementation detail
                        > that shouldn't be in the interface.

                        I don't think so. But please show us, why you think it is
                        better to name it a POSIX-module instead of Unix-module.


                        Ciao,
                        Oliver
                      • Adrien
                        ... Windows *is* posix-compliant while linux and free/netbsd aren t. Hard to believe, isn t it ? The point is there are posix certification and of course they
                        Message 11 of 29 , Nov 6, 2007
                          2007/11/6, Oliver Bandel <oliver@...-berlin.de>:
                          > > such as Windows (and
                          > > others).
                          >
                          > What's about fork and similar functions, that are available on Unix,
                          > but not on Windows?
                          > Isn't fork a part of POSIX-standards also?
                          > But it's available on Unix only, so I would think
                          > the name for that module is OK.
                          >

                          Windows *is* posix-compliant while linux and free/netbsd aren't. Hard
                          to believe, isn't it ?
                          The point is there are posix certification and of course they cost
                          money. As each change to the kernel would require a new bunch of test,
                          linux and free/netbsd simply don't try to be posix-certified (plus
                          linux lacks some features).
                          But how can windows be compliant ? Simply because there are several
                          versions of posix. "POSIX" is simply very vague :
                          http://www.gcn.com/print/14_23/31557-1.html


                          NT<5.1 (2000 and earlier versions) are more posix-compliant than
                          today's versions of windows.
                          You can see this page from MS about NT4 workstation entitled "Chapter
                          29 - POSIX Compatibility" :
                          http://www.microsoft.com/technet/archive/ntwrkstn/reskit/poscomp.mspx
                          (the page references hard links on ntfs : they work but appeared to be
                          buggy/unreliable when I used them)


                          However MS is removing this "subsystem"(1) from windows. Quoting
                          microsoft : http://support.microsoft.com/kb/308259/en-us
                          > The Portable Operating System for UNIX (POSIX) subsystem is not included with
                          > Windows XP or with Windows Server 2003. The POSIX subsystem has been
                          > replaced with a more UNIX-like environment that is named Windows Services for
                          > UNIX. Windows Services for UNIX is a superset of the original POSIX subsystem
                          > and provides greater functionality for UNIX programs. Windows Services for UNIX
                          > requires Windows XP Professional Service Pack 1 (SP1) or later.

                          (1) how was posix provided ?
                          I know there has been a registry setting to disable it which shows it
                          was a sort of module but I don't know the whole story as really used
                          it.


                          SFU (Services For Unix) is really appealing. I've first heard of it a
                          while ago when I used mingw but never used it because I didn't
                          understand it (hey, this was 4 years ago, I was 15 =P ). Now I look at
                          it again for this message, features are even more appealing than they
                          were one month ago. Such features are gcc 3.3, pthreads, shared,
                          linking unix programs with windows dlls
                          For a full list, see : http://en.wikipedia.org/wiki/Interix#Details


                          Nice. But there's something else one has to know :
                          From wikipedia's page on SFU (Services For Unix)
                          "Microsoft does not intend to produce any further standalone versions
                          of the product. SFU will be available for download[4] until 2009;
                          general support will continue until 2011; extended support until
                          2014[5]."

                          Something I don't know is the price of this.
                          Version 3.5 is free but it doesn't give the ability to link between
                          unix programs and windows dlls. Is the actual one free too ?
                          Microsoft won't continue to ship this with its server/workstation
                          editions of windows. How will it evolve ?


                          For more information, you can read this page (and forum):
                          http://www.interopcommunity.com/tm.aspx?m=5623
                          A starting point for SFU is wikipedia :
                          http://en.wikipedia.org/wiki/Windows_Services_for_Unix



                          I never used SFU because it appeared as a tool made for servers.
                          Therefore I can't give any impression or report how it works(2). I
                          won't dig into this right now either as I don't have enough time for
                          at least eight months.
                          What I fear is paths : windows's path separator '\' is an escape
                          character which shell scripts and ocaml don't like. Moreover you can
                          easily find $path1/$path2 in configure scripts and this simply won't
                          work correctly under windows (cygwin being an exception but cygwin is
                          emulation so it doesn't really count anyway).
                          (2) according to the audience of this tool, I guess it works well though...


                          I'll see quickly what SFU can offer us, but really not thoroughly.


                          ---

                          Adrien Nader
                        • Oliver Bandel
                          ... [...] No problem with that, that s not new to me (at least regarding Win-NT, I don t know if the new windows are also.). Because there are so many
                          Message 12 of 29 , Nov 7, 2007
                            Zitat von Adrien <camaradetux@...>:

                            > 2007/11/6, Oliver Bandel <oliver@...-berlin.de>:
                            > > > such as Windows (and
                            > > > others).
                            > >
                            > > What's about fork and similar functions, that are available on Unix,
                            > > but not on Windows?
                            > > Isn't fork a part of POSIX-standards also?
                            > > But it's available on Unix only, so I would think
                            > > the name for that module is OK.
                            > >
                            >
                            > Windows *is* posix-compliant while linux and free/netbsd aren't. Hard
                            > to believe, isn't it ?
                            [...]

                            No problem with that, that's not new to me (at least regarding Win-NT,
                            I don't know if the new windows' are also.).
                            Because there are so many POSIX-standards, one could look,
                            which system covers what... but for me that's not something,
                            that interests me enough to invest much time there.
                            I need a good working system, that is open and stable enough for my purposes
                            and gives me the power I need (instead that the system sucks my energy ;-)).



                            So we have: The Unix-module actually is a POSIX-module,
                            Windows is POSIX-compliant and Unix/Linux aren't.

                            And so we should rename the Unix-module to Windows-module,
                            and then all people are happy and we will have peace on earth.


                            Ciao,
                            Oliver
                          • Richard Jones
                            ... Who knows? How about using software which _you_ have control over, not some corporation that doesn t have your interests at heart. Rich. -- Richard Jones
                            Message 13 of 29 , Nov 7, 2007
                              On Tue, Nov 06, 2007 at 07:09:41PM +0100, Adrien wrote:
                              > Nice. But there's something else one has to know :
                              > >From wikipedia's page on SFU (Services For Unix)
                              > "Microsoft does not intend to produce any further standalone versions
                              > of the product. SFU will be available for download[4] until 2009;
                              > general support will continue until 2011; extended support until
                              > 2014[5]."
                              >
                              > Something I don't know is the price of this.
                              > Version 3.5 is free but it doesn't give the ability to link between
                              > unix programs and windows dlls. Is the actual one free too ?
                              > Microsoft won't continue to ship this with its server/workstation
                              > editions of windows. How will it evolve ?

                              Who knows? How about using software which _you_ have control over,
                              not some corporation that doesn't have your interests at heart.

                              Rich.

                              --
                              Richard Jones
                              Red Hat
                            • Fabrice Marchant
                              Hi ! There are four libraries : thread, mutex, events and conditions that are related to threads. I see very few programs that use such things. Apart Julien
                              Message 14 of 29 , Nov 9, 2007
                                Hi !

                                There are four libraries : thread, mutex, events and conditions that are related to threads.
                                I see very few programs that use such things. Apart Julien Signoles 'life' and Oliver Bandel 'newfaction',
                                there are :
                                http://freetennis.sourceforge.net/
                                (uses Events)
                                or 'Poesia' of Basile Starynkevitch.
                                They are however too much complicated to be studied as learning examples.

                                I imagine POSIX OCaml threads are about the same things than C threads ?
                                So a track could be looking for C threads examples ?

                                Cheers,

                                Fabrice
                                ----------------------------------------------------
                                OCaml is the best computer language I've ever tried.
                              • William D. Neumann
                                On Fri, 9 Nov 2007 17:24:02 +0100, Fabrice Marchant wrote ... Have you looked at the section on concurrent programming in the O Reilly book?
                                Message 15 of 29 , Nov 9, 2007
                                  On Fri, 9 Nov 2007 17:24:02 +0100, Fabrice Marchant wrote
                                  > Hi !

                                  > I imagine POSIX OCaml threads are about the same things than C
                                  > threads ? So a track could be looking for C threads examples ?

                                  Have you looked at the section on concurrent programming in the O'Reilly
                                  book? http://caml.inria.fr/pub/docs/oreilly-book/

                                  --

                                  William D. Neumann
                                • Fabrice Marchant
                                  On Fri, 9 Nov 2007 11:31:51 -0600 ... Thanks, I m reading it. Regards, Fabrice
                                  Message 16 of 29 , Nov 9, 2007
                                    On Fri, 9 Nov 2007 11:31:51 -0600
                                    "William D. Neumann" <wneumann@...> wrote:

                                    > On Fri, 9 Nov 2007 17:24:02 +0100, Fabrice Marchant wrote
                                    > > Hi !
                                    >
                                    > > I imagine POSIX OCaml threads are about the same things than C
                                    > > threads ? So a track could be looking for C threads examples ?
                                    >
                                    > Have you looked at the section on concurrent programming in the O'Reilly
                                    > book? http://caml.inria.fr/pub/docs/oreilly-book/
                                    Thanks,

                                    I'm reading it.

                                    Regards,

                                    Fabrice
                                  • Oliver Bandel
                                    ... [...] OK, I see, my example was TOO simple ;-) Nothing more to learn from it? ;-) But you asked for simple, and so you got ;-) Ciao, Oliver
                                    Message 17 of 29 , Nov 10, 2007
                                      Zitat von Fabrice Marchant <fabrice.marchant@...>:

                                      > Hi !
                                      >
                                      > There are four libraries : thread, mutex, events and conditions that are
                                      > related to threads.
                                      > I see very few programs that use such things. Apart Julien Signoles 'life'
                                      > and Oliver Bandel 'newfaction',
                                      > there are :
                                      [...]

                                      OK, I see, my example was TOO simple ;-)
                                      Nothing more to learn from it? ;-)
                                      But you asked for simple, and so you got ;-)

                                      Ciao,
                                      Oliver
                                    • Richard Jones
                                      ... The AdWords API uses both threads and events. However it also may not be so easy to study. http://merjis.com/developers/adwords_api ... Yup. Rich. --
                                      Message 18 of 29 , Nov 10, 2007
                                        On Fri, Nov 09, 2007 at 05:24:02PM +0100, Fabrice Marchant wrote:
                                        > They are however too much complicated to be studied as learning examples.

                                        The AdWords API uses both threads and events. However it also may
                                        not be so easy to study.

                                        http://merjis.com/developers/adwords_api

                                        > I imagine POSIX OCaml threads are about the same things than C threads ?
                                        > So a track could be looking for C threads examples ?

                                        Yup.

                                        Rich.

                                        --
                                        Richard Jones
                                        Red Hat
                                      • Fabrice Marchant
                                        On Sat, 10 Nov 2007 20:43:29 +0000 ... Thanks for the example. Not so easy indeed but of interest. Unfortunately, I m unable to compile with current OCaml, cos
                                        Message 19 of 29 , Nov 10, 2007
                                          On Sat, 10 Nov 2007 20:43:29 +0000
                                          Richard Jones <rich@...> wrote:

                                          > The AdWords API uses both threads and events. However it also may
                                          > not be so easy to study.
                                          >
                                          > http://merjis.com/developers/adwords_api

                                          Thanks for the example.

                                          Not so easy indeed but of interest. Unfortunately, I'm unable to compile with current OCaml, cos a camlp4 deprecated syntax on OC-SOAP.

                                          Regards,

                                          Fabrice
                                        • Richard Jones
                                          ... Heh, yes, that s what camlp5 is for :-) Actually that in itself isn t a very honest answer. AdWords API in general is deprecated because of the stupid
                                          Message 20 of 29 , Nov 10, 2007
                                            On Sat, Nov 10, 2007 at 10:29:08PM +0100, Fabrice Marchant wrote:
                                            > On Sat, 10 Nov 2007 20:43:29 +0000
                                            > Richard Jones <rich@...> wrote:
                                            >
                                            > > The AdWords API uses both threads and events. However it also may
                                            > > not be so easy to study.
                                            > >
                                            > > http://merjis.com/developers/adwords_api
                                            >
                                            > Thanks for the example.
                                            >
                                            > Not so easy indeed but of interest. Unfortunately, I'm unable to compile with current OCaml, cos a camlp4 deprecated syntax on OC-SOAP.

                                            Heh, yes, that's what camlp5 is for :-)

                                            Actually that in itself isn't a very honest answer. AdWords API in
                                            general is deprecated because of the stupid games that Google keep
                                            playing with backwards compatibility and small commercial users of the
                                            API. Since it's just better to steer clear of dealing with Google's
                                            APIs because of all the nonsense they have put us through, I'm not
                                            updating this library.

                                            Rich.
                                          Your message has been successfully submitted and would be delivered to recipients shortly.