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

Green Thread Experiment #2057

Open
11 tasks
davidwrighton opened this issue Oct 26, 2022 · 5 comments
Open
11 tasks

Green Thread Experiment #2057

davidwrighton opened this issue Oct 26, 2022 · 5 comments
Labels
area-green-threads Green threads Epic Groups multiple user stories. Can be grouped under a theme.

Comments

@davidwrighton
Copy link
Member

davidwrighton commented Oct 26, 2022

The CoreCLR team is experimenting with using green threads to support customers who are interesting in writing code in a synchronous style, but with the ability to suspend to a fairly small memory footprint when an asynchronous operation occurs. Green threads are

Experimental report published in #2398

@davidwrighton davidwrighton added the area-green-threads Green threads label Oct 26, 2022
@benaadams
Copy link
Member

Assume it could also have potential address this issue by @krwq Proposition: Stack bending?

@mangod9 mangod9 added the Epic Groups multiple user stories. Can be grouped under a theme. label Oct 28, 2022
@davidwrighton
Copy link
Member Author

@benadams, the current experiment as envisioned would allow for arbitrary stack growth (without any need for a magic function to all), but it's not at all clear that would be a practical approach in the long term to actually implement and make reliable. Very deep stacks introduce new, and interesting problems. My suspicion is that we'll actually need to have a constrained stack depth limit.

@mangod9 mangod9 added this to UserStories + Epics in Core-Runtime .net 9 Oct 31, 2022
@mangod9 mangod9 moved this from UserStories + Epics to Experiments in Core-Runtime .net 9 Jan 4, 2023
@ForkBug
Copy link

ForkBug commented Jun 7, 2023

@davidwrighton Hi David, is Green-Threads feature still active, or dead?
If active, how to handle the following scenario?

A coroutine c1 wants to write a disk and then update a UI button.
A thread t1 schedules this coroutine until the coroutine starts writing to disk.
According to @davidfowl 's Twitter, the writing operation is async.
That means c1 will release the thread t1.
t1 will schedule another coroutine c2. c2 may need 10 seconds to finish.

But after a half second, c1 has finished the disk writing and wants to get an execution.

What will Green-Threads do?

  1. Wait for the thread t1. This strategy will downgrade throughput. c1 have to wait for 9.5 seconds
  2. Another thread t2 will schedule c1. If t1 is the UI thread, the following operation -- updates a UI button -- will fail, due to t2 is not the UI thread.

The problem is, OS will set some resources, or restrictions(like UI, tls, mutex, etc.), at thread level.

How does Green-Threads handle this problem?

@NCLnclNCL
Copy link

@davidwrightonXin chào David, tính năng Green-Threads vẫn hoạt động hay đã ngừng hoạt động? Nếu đang hoạt động thì xử lý tình huống sau như thế nào?

Một coroutine c1 muốn ghi đĩa rồi cập nhật nút giao diện người dùng. Một luồng t1 lên lịch cho coroutine này cho đến khi coroutine bắt đầu ghi vào đĩa. Dựa theo@davidfowlcủa Twitter, thao tác viết không đồng bộ. Điều đó có nghĩa là c1 sẽ giải phóng luồng t1. t1 sẽ lên lịch cho một coroutine c2 khác. c2 có thể cần 10 giây để hoàn thành.

Nhưng sau nửa giây, c1 đã ghi xong đĩa và muốn thực thi.

Chủ Đề Xanh sẽ làm gì?

  1. Đợi chủ đề t1. Chiến lược này sẽ hạ thấp thông lượng. c1 phải đợi 9,5 giây
  2. Một luồng khác t2 sẽ lên lịch c1. Nếu t1 là luồng giao diện người dùng, thao tác sau -- cập nhật nút giao diện người dùng -- sẽ thất bại, do t2 không phải là luồng giao diện người dùng.

Vấn đề là, HĐH sẽ đặt một số tài nguyên hoặc hạn chế (như UI, tls, mutex, v.v.) ở cấp luồng.

Green-Threads xử lý vấn đề này như thế nào?

Wait

@davidwrighton
Copy link
Member Author

Experiment report has been published in #2398

@mangod9 mangod9 removed this from Experiments in Core-Runtime .net 9 Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-green-threads Green threads Epic Groups multiple user stories. Can be grouped under a theme.
Projects
None yet
Development

No branches or pull requests

5 participants