简体   繁体   中英

Event driven programming and Green thread: what is their relation?

It is not clear to me what is the relationship between the two: would be correct to say that event driven programming is a programming methodology and green threads as well as event libraries (like libev in c) follow this kind of method?

Event driven programming and green threads aren't directly related.

However; if a process using green threads calls a blocking system call the entire process (all of its green threads) will become blocked (and that would be horrible for performance). To work around that some form of asynchronous system calls must be used instead; but all asynchronous system calls must have some way of notifying the process that the status of asynchronous operation has changed (eg a notification sent by kernel to say "That file data you wanted to read asynchronously has been read successfully").

In other words, "events" (notifications from kernel saying that the status of asynchronous operation/s have changed) end up being important for the implementation of a well performing green thread run-time.

Of course the implementation of the run-time has little to do with what programmers using that run-time actually see. Eg programmers using the run-time might use blocking IO and not use any events or event driven programming (and that blocking IO may be emulated by a run-time using asynchronous IO and events/notifications).

Here is some information about the relation between event-driven programming and threads. What is event-driven programming?

I have no idea why to single out green threads in this regard, that's just a question of how threading is implemented. How did you get to your question?

To literally answer your last question: no, green threads don't follow an event-driven methodology.

Both envisage the usage of a loop that is why I was thinking about an analogy, both shouldn't use the OS scheduler to run (except for the fact thar run on main thread), if I am correct....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM