Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Windows, getcontext returns an error #11

Closed
dinosaure opened this issue Jun 1, 2022 · 7 comments
Closed

On Windows, getcontext returns an error #11

dinosaure opened this issue Jun 1, 2022 · 7 comments

Comments

@dinosaure
Copy link
Owner

It seems that getcontext returns a error and it's impossible for pth to spawn a new thread. Due to this error, a SEGFAULT is reached at one point where no threads was launched but pth_key_setdata expects a current one. I will try to find if the error come from Cosmopolitan or if it's a real barrier.

@dinosaure
Copy link
Owner Author

It seems not possible to use pth on Windows (it seems that only w32 is supported). More concretely, Cosmopolitan does not implement

  • mcsc machine context method (makecontext(3)/setcontext(3)) for Windows (ESYS is returned)
  • sas stack setup method (sigaltstack(2))
  • ss stack setup method (sigstack(2))

sjljw32 is available but it works only for a 32-bits architecture which is too restrictive for us. We have 2 ways to solve this issue:

  • implement required functions mcsc, sas or ss into Cosmopolitan
  • modify pth to provide a Windows implementation of pth_mctx - we probably need to use the mcsc compilation path and check if we are into IsWindows() and do something else than makecontext/setcontext

@dinosaure
Copy link
Owner Author

The required interface of pth_mctx is:

typedef struct pth_mctx_t pth_mctx_t;

pth_mctx_switch(pth_mctx_t* , pth_mctx_t *);
pth_mctx_restore(pth_mctx_t *);
pth_mctx_set(pth_mctx_t *, void (*f)(void), char *addr_lo, char *addr_hi);

@dinosaure
Copy link
Owner Author

The best possibily is to integrate winpthreads into pth and use IsWindows() to switch from one implementation to another depending on the platform (thx @dra27 for his help). OCaml multicore will use it too so we ensure a certain coherence between Esperanto and OCaml Multicore.

@jart
Copy link

jart commented Sep 30, 2022

@dinosaure Cosmopolitan Libc has pthreads support now. https://github.com/jart/cosmopolitan/releases/tag/2.1 If there's an issue with setcontext() and getcontext() that are causing issues for fibers, then let me know and I'll fix it.

@dinosaure
Copy link
Owner Author

Thanks @jart, I will probably focus on that in 2~3 weeks 👍 - It's currently on top of my TODO list.

@jart
Copy link

jart commented Oct 2, 2022

Awesome to hear! Looking forward to seeing where it goes.

@dinosaure
Copy link
Owner Author

FIxed by #28 which uses Cosmopolitan 2.2 (which has pthread_ functions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants