Looking for breakthrough ideas for innovation challenges? Try Patsnap Eureka!

Coroutine implementation method and apparatus

An implementation method and coroutine technology, applied in the field of coroutine implementation methods and devices, can solve the problems of complex implementation of coroutines, troublesome, complex implementation of yield keywords, etc., and achieve the effect of improving efficiency and reducing complexity.

Active Publication Date: 2018-05-04
TENCENT TECH (SHENZHEN) CO LTD
View PDF4 Cites 12 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0003] However, to implement a coroutine based on a Generator, the yield keyword of the Generator must be used (yield represents a renunciation and transfer of control); once the function corresponding to the coroutine uses the yield keyword, the upper-level calls of the function must use yield to call sub-function, and at the same time define the function call and function return semantics of the yield keyword; it can be seen that based on the Generator, using the yield keyword to implement the coroutine will bring in the complex problem of the yield keyword itself, resulting in the coroutine The implementation is more complicated and cumbersome, which reduces the efficiency of the implementation of the coroutine

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Coroutine implementation method and apparatus
  • Coroutine implementation method and apparatus
  • Coroutine implementation method and apparatus

Examples

Experimental program
Comparison scheme
Effect test

Embodiment Construction

[0028] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.

[0029] Different from the existing Generator-based method that uses the yield keyword to implement coroutines, the embodiment of the present invention can be based on a programming language (such as C language) at the bottom layer of a scripting language (such as the PHP language) development environment (such as the bottom layer of Zend), for The scripting language of the application layer and the extended development of the scripting language provide coroutin...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

Embodiments of the present invention provide a coroutine implementation method and apparatus. The method comprises: determining a target memory space required by a function call stack corresponding toa coroutine according to a script language byte code of a function corresponding to the coroutine, wherein one coroutine is corresponding to one function call stack; allocating an independent memoryspace corresponding to the target memory space for the function call stack, wherein the memory space of the function call stack corresponding to each coroutine does not interfere with each other; in the independent memory space, filling each structure of the function call stack with the content; preprocessing the function call stack before execution of the coroutine; and directing the execution state of the virtual machine to the function call stack so as to execute the coroutine. Further, the embodiments of the present invention can also implement coroutine switching. According to the embodiments of the present invention, the efficiency of the coroutine implementation can be improved.

Description

technical field [0001] The invention relates to the technical field of programs, in particular to a method and device for implementing a coroutine. Background technique [0002] As a reentrant subroutine in user mode, coroutines are widely used in computer programs and data processing; currently, the framework for integrating coroutine capabilities is generally realized through the function reentrant capability provided by Generator (iterator), that is, a Generator As a coroutine, it implements a coroutine scheduler at the application level. [0003] However, to implement a coroutine based on a Generator, the yield keyword of the Generator must be used (yield represents a renunciation and transfer of control rights); once the function corresponding to the coroutine uses the yield keyword, the upper-level calls of the function must use yield to call Sub-functions, and at the same time define the function call and function return semantics of the yield keyword; it can be seen...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
IPC IPC(8): G06F9/448
Inventor 朱新宇司超王广超袁易之杨锡坤
Owner TENCENT TECH (SHENZHEN) CO LTD
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Patsnap Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Patsnap Eureka Blog
Learn More
PatSnap group products