• Re: best approach for multithreading (?)

    From candycanearter07@21:1/5 to fir on Sun Dec 1 15:10:03 2024
    fir <profesor.fir@gmail.com> wrote at 22:04 this Saturday (GMT):
    [i wropte it soem days back then to eventually post in a place when
    people can answer this but i dont get idea of such place so i post it
    here for now]

    tell me if you know somethin better approach for multithreading
    than this

    i mean i got discovered soem approach for multithreadng
    (i mean scheme how it probably should be done) and i wonder
    if there is something better than this (in real world)

    the appriach is based on call queue and needs (at least
    as a base) two keywoards 'adq' (add queue) and 'runq' (run queue)
    ewentually 'runqs' (run queue sequantially) 'runqp' (run queue in
    parrallel)

    adq just adds a given adress of a function and its arguments
    in queue which is close to stack, say

    for(int i=0; i<5; i++)
    adq__ foo(i);

    stores


    foo, 0
    foo, 1
    foo, 2
    foo, 3
    foo, 4

    (40 bytes if foo is 32 bit adress, and i is 32 bit int)
    in ram

    runq

    then runs it (iterates and runs the functions)

    (both adq and runq are better implemented on language level,
    though they also probably can be implemented in some library)

    the thing is the runq dont need to run the things on one core
    and sequentially but it can just run the queue on as many cores
    as are avaliable

    no problem i think if those queued calls are not conflicting one witch another (like foo is draw_line_of_mandelbrot(i); ) but if the calls may
    be somewhat conflizting (on ram writes) there is an optio to add
    to addq also a number assigned to each call which will denote/mark
    this call to be not conflicting witch another call if the numbers are different and eventuallt be conflicting if the numbers are the same
    (like "1")
    then the cals of the same group should be run on one core in sequential
    but the
    other groups can each be called on its own core

    i did not used multithreading more than couple of days in my life
    so i know it slight but i never liked what i used to much and this
    approach seem to me best of what i heard..


    so is it he best approach or there is something better?

    /fir


    There's a standard library for multithreading. https://www.man7.org/linux/man-pages/man7/pthreads.7.html
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to All on Sun Dec 1 15:45:28 2024
    On Sun, 01 Dec 2024 15:10:03 +0000, candycanearter07 wrote:

    fir <profesor.fir@gmail.com> wrote at 22:04 this Saturday (GMT):
    [i wropte it soem days back then to eventually post in a place when
    people can answer this but i dont get idea of such place so i post it
    here for now]

    tell me if you know somethin better approach for multithreading
    than this

    i mean i got discovered soem approach for multithreadng
    (i mean scheme how it probably should be done) and i wonder
    if there is something better than this (in real world)

    the appriach is based on call queue and needs (at least
    as a base) two keywoards 'adq' (add queue) and 'runq' (run queue)
    ewentually 'runqs' (run queue sequantially) 'runqp' (run queue in
    parrallel)
    [snip]

    so is it he best approach or there is something better?

    /fir


    There's a standard library for multithreading. https://www.man7.org/linux/man-pages/man7/pthreads.7.html

    Since C11, the C standard library has provided it's own support for
    threading, which (I'm told) closely resembles the POSIX threading
    model implemented in the Linux pthreads library.

    Fir might check out the C standard first (as code written to that
    standard will be portable to any environment that supports C11).


    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Lew Pitcher on Sun Dec 1 15:54:03 2024
    On 2024-12-01, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
    On Sun, 01 Dec 2024 15:10:03 +0000, candycanearter07 wrote:
    There's a standard library for multithreading.
    https://www.man7.org/linux/man-pages/man7/pthreads.7.html

    Since C11, the C standard library has provided it's own support for threading, which (I'm told) closely resembles the POSIX threading
    model implemented in the Linux pthreads library.

    Yes; they stupidly took a chunk of POSIX (IEE 1003 standard, originally
    formed as a fork of C to standarize Unix things) and cloned an
    incompatible version with different types and function names.

    For over a decade before that, people were already using POSIX threads
    on platforms that don't have POSIX threads, via libraries.

    That's an excellent solution that moves out of the way on platforms
    where you do have POSIX threads.

    Standards cribbing from other standards, and changing things, is totally counterproductive.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Chris M. Thomasson on Tue Dec 3 17:48:01 2024
    On 2024-12-01, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
    On 12/1/2024 7:54 AM, Kaz Kylheku wrote:
    On 2024-12-01, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
    On Sun, 01 Dec 2024 15:10:03 +0000, candycanearter07 wrote:
    There's a standard library for multithreading.
    https://www.man7.org/linux/man-pages/man7/pthreads.7.html

    Since C11, the C standard library has provided it's own support for
    threading, which (I'm told) closely resembles the POSIX threading
    model implemented in the Linux pthreads library.

    Yes; they stupidly took a chunk of POSIX (IEE 1003 standard, originally
    formed as a fork of C to standarize Unix things) and cloned an
    incompatible version with different types and function names.

    For over a decade before that, people were already using POSIX threads
    on platforms that don't have POSIX threads, via libraries.

    Here is one I used to always use back in the day over on Windows:

    https://sourceware.org/pthreads-win32/

    And that is not significantly harder to implement (if at all) than C11 threading.

    Think about it. The POSIX standard includes ISO C by reference.
    So that means POSIX has to have two thread libraries.
    It's a waste of flash in embedded systems.


    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Kaz Kylheku on Thu Dec 5 19:09:39 2024
    On 12/3/24 12:48, Kaz Kylheku wrote:
    ...
    Think about it. The POSIX standard includes ISO C by reference.
    So that means POSIX has to have two thread libraries.
    It's a waste of flash in embedded systems.

    C <threads.h> can be implemented as a thin wrapper over POSIX threads.
    The waste is relatively negligible. The differences, were intended to
    allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to James Kuyper on Fri Dec 6 03:14:13 2024
    On 2024-12-06, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 12/3/24 12:48, Kaz Kylheku wrote:
    ...
    Think about it. The POSIX standard includes ISO C by reference.
    So that means POSIX has to have two thread libraries.
    It's a waste of flash in embedded systems.

    C <threads.h> can be implemented as a thin wrapper over POSIX threads.
    The waste is relatively negligible. The differences, were intended to
    allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    Generally speaking, you can have a function called pthread_create on
    non-POSIX systems, and a header <pthread.h>.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Kaz Kylheku on Fri Dec 6 16:10:39 2024
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-12-06, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 12/3/24 12:48, Kaz Kylheku wrote:
    ...
    Think about it. The POSIX standard includes ISO C by reference.
    So that means POSIX has to have two thread libraries.
    It's a waste of flash in embedded systems.

    C <threads.h> can be implemented as a thin wrapper over POSIX threads.
    The waste is relatively negligible. The differences, were intended to
    allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    Generally speaking, you can have a function called pthread_create on >non-POSIX systems, and a header <pthread.h>.

    There are certain requirements of a posix threads implementation that
    might be impossible for a non-POSIX system to implement efficiently;
    windows, for example, doesn't support signals.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Scott Lurndal on Fri Dec 6 18:20:54 2024
    On 2024-12-06, Scott Lurndal <scott@slp53.sl.home> wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-12-06, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 12/3/24 12:48, Kaz Kylheku wrote:
    ...
    Think about it. The POSIX standard includes ISO C by reference.
    So that means POSIX has to have two thread libraries.
    It's a waste of flash in embedded systems.

    C <threads.h> can be implemented as a thin wrapper over POSIX threads.
    The waste is relatively negligible. The differences, were intended to
    allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    Generally speaking, you can have a function called pthread_create on >>non-POSIX systems, and a header <pthread.h>.

    There are certain requirements of a posix threads implementation that
    might be impossible for a non-POSIX system to implement efficiently;
    windows, for example, doesn't support signals.

    It's better to remove requirements from the POSIX standard to implement
    a useful subset of POSIX threads, than to remove requirements from POSIX threads and then change all the names to ISO C threads, to create a
    redundant specification.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Scott Lurndal on Sat Dec 7 00:16:20 2024
    On 12/6/24 11:10, Scott Lurndal wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-12-06, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    ...
    C <threads.h> can be implemented as a thin wrapper over POSIX threads.
    The waste is relatively negligible. The differences, were intended to
    allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    Generally speaking, you can have a function called pthread_create on
    non-POSIX systems, and a header <pthread.h>.

    There are certain requirements of a posix threads implementation that
    might be impossible for a non-POSIX system to implement efficiently;
    windows, for example, doesn't support signals.

    My words above not-withstanding, I am not in any sense an expert on any
    kind of threading, nor of Windows. What does POSIX require of threads
    with regards to signals?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to James Kuyper on Sat Dec 7 06:10:57 2024
    James Kuyper <jameskuyper@alumni.caltech.edu> writes:

    My words above not-withstanding, [...]

    In English, notwithstanding is a single word, not a two-word
    hyphenation, and has been for hundreds of years.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to James Kuyper on Sun Dec 8 03:49:29 2024
    On 2024-12-07, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 12/6/24 11:10, Scott Lurndal wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-12-06, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    ...
    C <threads.h> can be implemented as a thin wrapper over POSIX threads. >>>> The waste is relatively negligible. The differences, were intended to
    allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    Generally speaking, you can have a function called pthread_create on
    non-POSIX systems, and a header <pthread.h>.

    There are certain requirements of a posix threads implementation that
    might be impossible for a non-POSIX system to implement efficiently;
    windows, for example, doesn't support signals.

    My words above not-withstanding, I am not in any sense an expert on any
    kind of threading, nor of Windows. What does POSIX require of threads
    with regards to signals?

    Off the top of my head, the highlights:

    - threads have their own signal masks, inherited from the creator which
    calls pthtead_create.
    - signal masks can be manipulated so that a given signal will be
    handled in the context of a desired thread.
    - sigwait (and several other functions) can be used by a thread to
    wait for one or more signals, allowing signals to be process
    synchronously, somewhat like message passing.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Chris M. Thomasson on Sun Dec 8 09:31:45 2024
    On 2024-12-08, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
    On 12/7/2024 7:49 PM, Kaz Kylheku wrote:
    On 2024-12-07, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    My words above not-withstanding, I am not in any sense an expert on any
    kind of threading, nor of Windows. What does POSIX require of threads
    with regards to signals?

    Off the top of my head, the highlights:

    - threads have their own signal masks, inherited from the creator which
    calls pthtead_create.
    - signal masks can be manipulated so that a given signal will be
    handled in the context of a desired thread.
    - sigwait (and several other functions) can be used by a thread to
    wait for one or more signals, allowing signals to be process
    synchronously, somewhat like message passing.


    Semaphores are sig safe, so to speak. It's been a while:

    https://www.man7.org/linux/man-pages/man3/sem_post.3.html

    should be sig safe? Or, am I wrong here Kaz?

    Yes; just not sem_wait. The obvious idea there is that a signal handler
    is like an interrupt service top half, and those must be able to bang semaphores, to wake up something waiting in the bottom half code.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Waldek Hebisch@21:1/5 to Kaz Kylheku on Mon Dec 9 00:39:18 2024
    Kaz Kylheku <643-408-1753@kylheku.com> wrote:
    On 2024-12-07, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    On 12/6/24 11:10, Scott Lurndal wrote:
    Kaz Kylheku <643-408-1753@kylheku.com> writes:
    On 2024-12-06, James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
    ...
    C <threads.h> can be implemented as a thin wrapper over POSIX threads. >>>>> The waste is relatively negligible. The differences, were intended to >>>>> allow <threads.h> to also be implemented on non-POSIX systems as
    wrappers for whatever the native threading system was.

    Generally speaking, you can have a function called pthread_create on
    non-POSIX systems, and a header <pthread.h>.

    There are certain requirements of a posix threads implementation that
    might be impossible for a non-POSIX system to implement efficiently;
    windows, for example, doesn't support signals.

    My words above not-withstanding, I am not in any sense an expert on any
    kind of threading, nor of Windows. What does POSIX require of threads
    with regards to signals?

    Off the top of my head, the highlights:

    - threads have their own signal masks, inherited from the creator which
    calls pthtead_create.
    - signal masks can be manipulated so that a given signal will be
    handled in the context of a desired thread.
    - sigwait (and several other functions) can be used by a thread to
    wait for one or more signals, allowing signals to be process
    synchronously, somewhat like message passing.

    Hmm, as long as there is no way to generate signals the above
    can be implemented as a no-op or close (say possibly storing
    mask somewhere so that application can get it back). Of
    course, it would be harder if Windows has signals or if
    POSIX requires ability to generate signals.

    --
    Waldek Hebisch

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)