Go Lang Learning notes--channel mechanism and scheduling comprehension

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. "Go Language Programming" introduces the Libtask library, you can think of this library as equivalent to the bottom goroutine implementation of go. of the Libtask library The channel data structure is as follows:
 
 
  1. struct Alt
  2. {
  3. Channel *c;
  4. void *v;
  5. unsigned int op;
  6. Task *task;
  7. Alt *xalt;
  8. };
  9. struct Altarray
  10. {
  11. Alt **a;
  12. unsigned int n;
  13. unsigned int m;
  14. };
  15. struct Channel
  16. {
  17. unsigned int bufsize;
  18. unsigned int elemsize;
  19. unsigned char *buf;
  20. unsigned int nbuf;
  21. unsigned int off;
  22. Altarray asend;
  23. Altarray arecv;
  24. char *name;
  25. };

We can see that the basic composition of the channel is as follows: Memory cache, for storing elements, sending queue, accepting queue.
The book lists the channel structure without in-depth explanation of how to communicate on the channel structure. In fact, combined with the contents of the book described in the previous Task (association) of the communication process has been made clear. But from the learner's point of view, of course, the more you explain the problem, the better. Next I try to explain how the task (coprocessor) communicates on this channel basis. For a situation where data is written to the channel:


For a situation where the data is read from the channel:


Note: The above two processes are based on the work principle of the association and the channel data structure after the introduction of my personal brain complement, and did not go through the Libtask code. There is a good chance that these two processes should be used as a reference to understand how the process works.


From for notes (Wiz)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.