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

Compiling the -t unix target with -thread or -vmthread #861

Closed
cfcs opened this Issue Oct 25, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@cfcs
Copy link

cfcs commented Oct 25, 2017

Hello!

I'm trying to figure out how to get my unikernel compiled with -thread with -t unix to enable usage of the threads library.

With -t macosx it gets added automatically:
https://github.com/mirage/mirage/blob/master/lib/mirage.ml#L1764

For most other targets (except Unix and MacOSX) the threads library is blacklisted:
https://github.com/mirage/mirage/blob/master/lib/mirage.ml#L1773-L1774

Is there an inherent incompatibility with threads/vmthreads/-thread and -t unix, or could you consider adding the flag, or adding some way to enable it for unix?

PS: While we're looking at this code, is there a reason the warn_errorflag doesn't allow the developer to specify the warnings they're interested in?

@cfcs cfcs changed the title MirageOS: Compiling the unix target with -thread or -vmthread Compiling the -t unix target with -thread or -vmthread Oct 25, 2017

@cfcs

This comment has been minimized.

Copy link
Author

cfcs commented Oct 25, 2017

Note: Naively patching it to add it to -t unix works like a charm, at least for me:

 (match target with `Unix | `MacOSX -> ["thread"] | _ -> []) @

But I don't know if there's a hidden cost to this to warrant a flag.

@yomimono

This comment has been minimized.

Copy link
Member

yomimono commented Nov 17, 2017

Hm, you're right that this is pretty inconsistent. threads is blacklisted on solo5 and xen targets because it relies on OS primitives that aren't available there. It's not included with -t unix because there's an assumption that if you're building stuff with mirage, it's because you eventually want to deploy it somewhere as a unikernel, and you probably want to find out quickly if you're depending on something that won't be available. I'm surprised that it's included for -t macosx; I would've assumed the behavior would be the same as -t unix.

I don't know much about the interaction of the lwt event loop with thread, but that's what I'd be most worried about in this scenario.

PS: While we're looking at this code, is there a reason the warn_errorflag doesn't allow the developer to specify the warnings they're interested in?

I don't think there's a particularly good reason; I'd certainly merge a good PR that made it more controllable.

@cfcs

This comment has been minimized.

Copy link
Author

cfcs commented Nov 17, 2017

Re: Threads: I suspect you're right that running multiple OCaml threads using Lwt.t could cause problems (I have no basis for making this uneducated guess though).

In my case I wanted to link my code against https://github.com/dbuenzli/tsdl which didn't seem to work without -thread.

@hannesm

This comment has been minimized.

Copy link
Member

hannesm commented Jul 29, 2018

I'm not an expert on -thread (-vmthread seems to be byte-code only which mirage currently doesn't target), but I've seen warnings ocamlfind: [WARNING] Package `threads': Linking problems may arise because of the missing -thread or -vmthread switch when compiling a unikernel with the unix target. in this case, lwt uses posix threads afaict. making it short: I added -tags thread in 72659cd.

hannesm added a commit to hannesm/mirage that referenced this issue Jul 29, 2018

@cfcs cfcs closed this Jul 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.