Arc Forumnew | comments | leaders | submitlogin
1 point by zhtw 6060 days ago | link | parent

Yes, thanks, it must work. But it means that you need to have exactly N suspended threads when you're waiting for data from N sockets. Thread pool helps a lot but in worst case you will still need exactly N threads.


2 points by almkglor 6060 days ago | link

Thread management is done automatically for you by the underlying mzscheme. A bit more of research seems to suggest that mzscheme can actually handle blocking I/O even if it uses green threads, and it can also have OS threads if compiled with support for it.

From what little I could grok from http://download.plt-scheme.org/doc/insidemz/insidemz-Z-H-8.h... it seems that there's not much overhead per thread anyway.

What are your concerns?

-----

3 points by soegaard 6059 days ago | link

MzScheme does not use OS threads. A long time ago it did, but it is pretty hard to make it work on Windows, OS X and Linux at the same time. Also context switching becomes cheaper without OS threads.

If you have found anything on OS threads in "Inside MzScheme" it must be in the section on how to embed MzScheme into a C program (with its own thread).

-----

1 point by zhtw 6059 days ago | link

Oh, is that rather usual that scheme implementation uses green threads? If so, maybe I really shouldn't worry about it. I was concerned only because I thought it was expensive to have one system thread per connection.

Thanks for the link.

-----

1 point by soegaard 6059 days ago | link

Most Scheme implementations doesn't use OS threads due to the cost of context switches. It is standard practice to use one thread for each connection.

See for example this very well written introduction to Systems Programming with PLT Scheme:

http://pre.plt-scheme.org/docs/html/more/index.html

-----

1 point by almkglor 6059 days ago | link

Maybe, I'm not sure. I couldn't grok the doc much. AFAIK mzscheme uses green threads only if it isn't compiled with "better" thread support.

As for cost per thread - no, I don't worry about it, it seems that mzscheme threads are reasonably light.

-----