• Re: more CMA

    From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.os.vms on Mon Dec 8 20:55:36 2025
    From Newsgroup: comp.os.vms

    In article <69345887$0$663$14726298@news.sunsite.dk>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 12/4/2025 3:59 PM, Arne Vajh|+j wrote:
    On 12/4/2025 2:49 PM, Simon Clubley wrote:
    1) What is the reason for using the CMA interface instead of the pthread >>> interface ? If there is no specific reason, perhaps rewriting it as a
    pthreads application might give some clues.

    I already have working pthreads code.

    I wanted to do the same with cma.

    There are something in cma not present in pthread.

    The cma API comes with the cma_lib_queue_* functions.

    Presumably this doesn't exist in pthreads because it's simple to
    do oneself using the tools that interface gives you (mutexes and
    condition variables, specifically).

    For example, I whipped this up earlier today as a demonstration: https://github.com/dancrossnyc/cqueue/blob/main/cqueue.c

    (The `try_*` implementations left as an exercise for the reader;
    they are very simple, but I just could't be bothered.)

    Nothing in the CMA lib APIs strikes me as particularly worth
    adding it to the interface, and one can imagine all sorts of
    enhancements that it just doesn't provide (prioritization;
    fairness; sending by value instead of reference, etc).

    For non-trivial applications, I imagine the pthreads folks
    decided that it was probably better to do it yourself, or find
    a third-party library better suited to the specific use case.

    Doing similar to java.util.concurrent.BlockingQueue
    if you are familiar with that.

    Well, not quite. That's generic over some element type, E. The
    CMA library functions, and my own trivial example, just use a
    pointer, which is rather different.

    - Dan C.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From =?UTF-8?Q?Arne_Vajh=C3=B8j?=@arne@vajhoej.dk to comp.os.vms on Mon Dec 8 21:06:40 2025
    From Newsgroup: comp.os.vms

    On 12/8/2025 3:55 PM, Dan Cross wrote:
    In article <69345887$0$663$14726298@news.sunsite.dk>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    There are something in cma not present in pthread.

    The cma API comes with the cma_lib_queue_* functions.

    Presumably this doesn't exist in pthreads because it's simple to
    do oneself using the tools that interface gives you (mutexes and
    condition variables, specifically).

    It is almost always possible to go DIY.

    But why? If someone else is willing to do it, then it is great!

    Nothing in the CMA lib APIs strikes me as particularly worth
    adding it to the interface, and one can imagine all sorts of
    enhancements that it just doesn't provide (prioritization;
    fairness; sending by value instead of reference, etc).

    Don't let perfect be the enemy of good.

    Doing similar to java.util.concurrent.BlockingQueue
    if you are familiar with that.

    Well, not quite. That's generic over some element type, E. The
    CMA library functions, and my own trivial example, just use a
    pointer, which is rather different.

    The Java version is more type safe than the C version.

    But I think that matches the preference of both Java and C
    people.

    Arne

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From cross@cross@spitfire.i.gajendra.net (Dan Cross) to comp.os.vms on Tue Dec 9 04:46:11 2025
    From Newsgroup: comp.os.vms

    In article <10h807g$hm6v$2@dont-email.me>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    On 12/8/2025 3:55 PM, Dan Cross wrote:
    In article <69345887$0$663$14726298@news.sunsite.dk>,
    Arne Vajh|+j <arne@vajhoej.dk> wrote:
    There are something in cma not present in pthread.

    The cma API comes with the cma_lib_queue_* functions.

    Presumably this doesn't exist in pthreads because it's simple to
    do oneself using the tools that interface gives you (mutexes and
    condition variables, specifically).

    It is almost always possible to go DIY.

    But why? If someone else is willing to do it, then it is great!

    Because by doing so, one conflates mechanism and policy, and one
    runs the risk of choosing the existing policy implementation in
    places where it's really not appropriate, simply because that's
    what's already there.

    Nothing in the CMA lib APIs strikes me as particularly worth
    adding it to the interface, and one can imagine all sorts of
    enhancements that it just doesn't provide (prioritization;
    fairness; sending by value instead of reference, etc).

    Don't let perfect be the enemy of good.

    Sure. But the hard part of software engineering is finding the
    right balance between adopting canned solutions to common
    problems juxtaposted with forcing a particular design "shape"
    onto programs.

    Threads are a basic building block for concurrent programs; they
    are mechanism, and as such, it makes sense to provide some
    primitive exposing them, particularly on systems where a thread
    is an OS-managed object. On the other hand, the specific
    implementation of queues is a lot closer to policy, for the
    aforementioned reasons (a queue for a particular application may
    want to take into account priority of queued items, or fairness
    and hysteresis with respect to scheduling produces and
    consumers, etc). Thus, it makes less sense to provide them as a
    library abstraction.

    Doing similar to java.util.concurrent.BlockingQueue
    if you are familiar with that.

    Well, not quite. That's generic over some element type, E. The
    CMA library functions, and my own trivial example, just use a
    pointer, which is rather different.

    The Java version is more type safe than the C version.

    But I think that matches the preference of both Java and C
    people.

    Generics gove a measure od type safety not managable in C.

    - Dan C.

    --- Synchronet 3.21a-Linux NewsLink 1.2