unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Damien Mattei <damien.mattei@gmail.com>, guile-user <guile-user@gnu.org>
Subject: Re: fibers,questions about thread id and mutation of vectors
Date: Fri, 6 Jan 2023 15:12:57 +0100	[thread overview]
Message-ID: <a21ee4b1-20ce-4229-882a-d7cde6d060fd@telenet.be> (raw)
In-Reply-To: <CADEOadcJmiNnDe2Vh98aZBFOMufH0oJvbDOPsx=nnGv8hwJ61A@mail.gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 2026 bytes --]



On 06-01-2023 11:20, Damien Mattei wrote:
> Hi,
> is fibers having a way to know the thread number the code is running?
> i, mean the equivalent of omp_get_thread_num(); in openMP.

There's (current-thread), but that's just Guile; it's not 
Fibers-specific.  It's also not a number.  I don't know if it's 
equivalent to omp_get_thread_num.

> Does vector-set! (i read the mutation section of the docand i suppose it is
> wrapped/rewritten for fibers) in fibers

What docs?  Guile fibers doesn't rewrite vector-set!.  I don't see what 
reason it would have to rewrite vector-set! at all.  The only thing it 
rewrites is the suspendable ports stuff, but that's irrelevant here. 
Could you quote the relevant part of the documentation?

> let many thread access a vector
> without time penalty if the index access are differents? (because if index
> are different there is no real concurrency)

I've heard there is some kind of CPU cache migration penalty when 
mutating and reading nearby regions of memory from different CPUs, but 
that's CPU stuff, not fibers-specific or even Guile-specific stuff.

Going by your previous question 'does fibers have a way to determine the 
thread is running on', I'm assuming your vector has entries per-thread 
and the fibers modify the per-thread entry (maybe some kind of 
accumulator?).

Regardless of the time penalty, it's probably unsafe, because due to 
scheduling, the thread on which a fiber runs can change over time -- 
between determining the index and writing to the vector, the thread can 
have changed.  So you'd have to do 'atomic-box-compare-and-swap!' stuff, 
but then you have a time penalty.  Or use 'call-with-blocked-asyncs' 
appropriately to temporarily block preemption.

Anyway, this reads as an 'XY problem' 
(https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378); 
instead of asking about your attempted solution, could you say what 
problem you are trying to solve?

Greetings,
Maxime.

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  reply	other threads:[~2023-01-06 14:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 10:20 fibers,questions about thread id and mutation of vectors Damien Mattei
2023-01-06 14:12 ` Maxime Devos [this message]
2023-01-06 15:06   ` Damien Mattei
2023-01-06 17:06     ` Damien Mattei
2023-01-06 17:06     ` Maxime Devos
2023-01-13 11:10       ` Damien Mattei
2023-01-13 12:23         ` Maxime Devos
2023-01-17  9:42           ` Damien Mattei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a21ee4b1-20ce-4229-882a-d7cde6d060fd@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).