unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Send scheme procedure as callback to foreign thread.
@ 2022-10-11  6:37 Zhu Zihao
  2022-10-12 20:54 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Zhu Zihao @ 2022-10-11  6:37 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 616 bytes --]

In Guile FFI programming, we have procedure->pointer, which makes a
Scheme procedure a foreign callback. And foreign library call use this
callback.

However, if this callback is called in a another foreign thread. The scheme
context is not properly setup, It may cause crash or UB.

IIUC, the procedure invoker "invoke_closure" defined in foreign.c
doesn't use scm_with_guile. If we use scm_with_guile to make a foreign
callback, would it be OK to execute Scheme procedure in multithreading context?
-- 
Retrieve my PGP public key:

  gpg --recv-keys B3EBC086AB0EBC0F45E0B4D433DB374BCEE4D9DC

Zihao

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Send scheme procedure as callback to foreign thread.
  2022-10-11  6:37 Send scheme procedure as callback to foreign thread Zhu Zihao
@ 2022-10-12 20:54 ` Ludovic Courtès
  2022-10-13 16:28   ` Zhu Zihao
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2022-10-12 20:54 UTC (permalink / raw)
  To: Zhu Zihao; +Cc: guile-devel

Hi,

Zhu Zihao <all_but_last@163.com> skribis:

> In Guile FFI programming, we have procedure->pointer, which makes a
> Scheme procedure a foreign callback. And foreign library call use this
> callback.
>
> However, if this callback is called in a another foreign thread. The scheme
> context is not properly setup, It may cause crash or UB.
>
> IIUC, the procedure invoker "invoke_closure" defined in foreign.c
> doesn't use scm_with_guile. If we use scm_with_guile to make a foreign
> callback, would it be OK to execute Scheme procedure in multithreading context?

Yes, it should be.

Could you come up with a minimal reproducer and maybe even a fix, now
that you likely found the solution?  :-)

Thanks in advance,
Ludo’.

PS: It may be best to use bug-guile to reduce the chances that the issue
    gets lost.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Send scheme procedure as callback to foreign thread.
  2022-10-12 20:54 ` Ludovic Courtès
@ 2022-10-13 16:28   ` Zhu Zihao
  0 siblings, 0 replies; 3+ messages in thread
From: Zhu Zihao @ 2022-10-13 16:28 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]


Thanks for your help!

I submit a more detailed report to https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58498.
-- 
Retrieve my PGP public key:

  gpg --recv-keys B3EBC086AB0EBC0F45E0B4D433DB374BCEE4D9DC

Zihao

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-13 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11  6:37 Send scheme procedure as callback to foreign thread Zhu Zihao
2022-10-12 20:54 ` Ludovic Courtès
2022-10-13 16:28   ` Zhu Zihao

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).