A method and apparatus for sharing information

By adding keywords to the application source code to indicate shared variables across multiple devices, and by using the compiler to automatically generate auxiliary variables and target code, the development complexity of information synchronization between multiple devices is solved, achieving more efficient information sharing and synchronization.

CN114968352BActive Publication Date: 2026-05-29HUAWEI TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2021-02-27
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In existing technologies, when applying information synchronization between multiple devices, developers need to manually write complex code, resulting in a large workload and a high probability of errors.

Method used

By adding keywords to the application's source code to indicate that variables are shared across multiple devices, the compiler can automatically generate auxiliary variables and target code, enabling the sharing and synchronization of variables across multiple devices.

Benefits of technology

It reduces the workload of developers, decreases code complexity and error probability, and improves development efficiency and quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114968352B_ABST
    Figure CN114968352B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a kind of method and device for sharing information, it is related to terminal technical field, can reduce the development difficulty of information shared between equipment, improve development quality.Specific scheme is: determine the code corresponding to the first variable in the source code of application includes keyword, keyword is used to indicate that the first variable is multi-device shared variable;First target code corresponding to auxiliary variable associated with the first variable is generated, and the auxiliary variable is used to support the first variable shared between multiple devices when the application runs on multiple devices.The embodiment of the present application is used in the process of writing application code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal technology, and in particular to a method and apparatus for sharing information. Background Technology

[0002] Currently, an application may run simultaneously on multiple devices. To provide a better user experience, these devices need to exchange information to keep the user's usage synchronized across all devices. However, currently, developers need to write their own code to handle this information synchronization when developing applications. For example, if a map application runs on both a mobile phone and a car's infotainment system, and the user sets navigation to address A in the mobile phone's map application, the map application developer needs to write code to synchronize the constantly changing location information monitored on the mobile phone's map application to the car's infotainment system in order for the user's location information to be displayed synchronously on the car's infotainment system. Similarly, the user's actions on the map application in the car's infotainment system also require the developer to write code to synchronize the constantly changing location information monitored on the car's map application to the mobile phone.

[0003] With the development of the internet, many similar applications encounter the scenarios described above in daily life. To achieve a better user experience in these scenarios, developers of various applications need to develop similar functionalities. However, this results in a significant workload for each application, as all information transmission and synchronization operations between devices require developers to code, demanding higher development skills and producing more complex code, thus increasing the possibility of errors during synchronization. Summary of the Invention

[0004] This application provides a method and apparatus for sharing information, which can reduce the development difficulty of sharing information between devices and improve development quality.

[0005] To achieve the above objectives, the embodiments of this application adopt the following technical solutions:

[0006] In a first aspect, a method for sharing information is provided, comprising: determining that the code corresponding to a first variable in the source code of an application includes a keyword, the keyword being used to indicate that the first variable is a multi-device shared variable; generating first target code corresponding to an auxiliary variable associated with the first variable, the auxiliary variable being used to support the sharing of the first variable among multiple devices when the application is running on multiple devices.

[0007] In existing technologies, developers first write software specifications in the source code. These specifications include multiple variables. If these variables need to be shared across multiple devices (i.e., shared variables exist), this application allows adding keywords to the source code of the shared variables. Developers no longer need to write source code for other auxiliary variables associated with the shared variables containing the keywords. When the compiler compiles the target code based on the developer's source code, if it determines that the source code of the shared variables carries keywords, it can generate target code for the auxiliary variables related to the shared variables according to a pre-defined compilation framework. This saves developers' coding workload, reduces the complexity of code compilation, and consequently reduces the possibility of coding errors.

[0008] In one possible design, the method further includes: generating second target code for the application based on the code corresponding to the first variable and the first target code. This second target code is used to determine the master device among multiple devices when the application runs on multiple devices. For example, determining the master device among multiple devices could be implemented as follows: among multiple devices interconnected on the same network, the device that first runs the application can be considered the master device by default, and subsequent devices running the application are considered non-master devices. When the master device malfunctions and needs to leave the network, a device that joined the network from other devices or the device that first ran the application from among those other devices can be designated as the new master device. While the master device is working normally, non-master devices can also request to become the new master device, and the master device can grant or deny the request based on its own operational status. In this way, the target code for determining the master device can also be automatically generated by the compiler based on the shared source code and the second target code, eliminating the need for developers to write the source code corresponding to the second target code, thus saving developers' workload.

[0009] In one possible design, the method further includes generating third target code based on the code corresponding to the first variable and the first target code. This third target code is used when the application runs on multiple devices to read the value of the first variable across these devices. For example, the third target code can implement the following: the master device stores the latest value of a shared variable across multiple devices, and the master device can directly read the value of the shared variable locally; when a non-master device needs to read the value of the shared variable, it needs to obtain it from the master device. This could be achieved by the master device directly notifying other non-master devices of the value of the shared variable, or by the non-master device requesting the value of the shared variable from the master device, ensuring consistency across devices. In this way, the code for any device in the multiple devices to read the shared variable can also be automatically completed by the compiler, eliminating the need for developers to write the source code corresponding to the third target code, thus saving developers' workload.

[0010] In one possible design, the method further includes generating fourth target code based on the code corresponding to the first variable and the first target code. This fourth target code is used when the application runs on multiple devices to modify the value of the first variable across devices. For example, the fourth target code can be used to achieve the following: when the master device in a multi-device environment needs to modify the value of a shared variable, it can directly modify the value of the shared variable locally, and also modify the value of the version identifier variable. When a non-master device needs to modify the value of a local shared variable, to prevent other devices from modifying it simultaneously and causing errors, the non-master device can first request to lock the variable from the master device. That is, even if the master device receives a modification request from another device, it must update the variable value according to the request from the non-master device that first locked the variable. After requesting to lock the variable, the non-master device can send the modified value to the master device so that the master device can save the modified value, ensuring consistency of the shared variable value across multiple devices. In this way, any device in a multi-device environment can automatically modify the value of a shared variable, without requiring developers to write the source code corresponding to the fourth target code, saving developers' workload.

[0011] In one possible design, auxiliary variables include variables indicating whether it is a master device, variables indicating the version identifier of the first variable, and variables indicating the sharing mode of the first variable among multiple devices. That is, when multiple devices share information, there are master devices and non-master devices among them. Both master and non-master devices can modify the value of the local shared variable. The version identifier variable can be understood as the number of times the shared variable has been modified locally. There are several ways to implement the sharing mode: for example, in one mode, if any device in the multiple devices needs to modify the value of the shared variable, that device needs to send a notification to the other devices in the multiple devices to inform them of the latest value of the shared variable, resulting in good data consistency among the multiple devices. In another mode, if any device in the multiple devices modifies the value of the shared variable, it only needs to notify the master device; other non-master devices can request the information from the master device when they need to synchronize information. In this way, when developers write shared variables (first variables) with keywords in their source code, the compiler can automatically generate the auxiliary variables related to the shared variables, saving developers' coding workload.

[0012] In one possible design, the auxiliary variable is used to indicate the sharing mode of the first variable across multiple devices. The sharing mode can be either a first mode or a second mode. In the first mode, when the first device modifies the value of the first variable locally, it notifies the other devices in the multi-device network of this event. In the second mode, when the second device modifies the value of the first variable locally, it notifies the master device in the multi-device network of this event, and the other devices in the multi-device network retrieve the value of the first variable from the master device. That is, the implementation of the auxiliary variable's sharing mode is also automatically compiled by the compiler.

[0013] In one possible design, the second target code is used to implement the following: In the multi-device setup, the device that first runs the application can be designated as the master device, and other devices that do not run the application can be designated as non-master devices; if the master device malfunctions and needs to exit the multi-device connection, the device that joined the network connection earliest among the other devices can be designated as the new master device; while the master device is working normally, non-master devices can apply to become the new master device, and the current master device can allow or deny the application based on its own circumstances.

[0014] In one possible design, the third target code is used to implement: the master device can directly read the value of the first variable from the master device; the value of the first variable stored on the master device is the latest updated value; if a non-master device wants to read the latest value of the first variable, it needs to read it from the master device and then use it to maintain the device state corresponding to the latest value.

[0015] In one possible design, the fourth object code is used to implement the following: When the device state of an application on the master device changes, or when the network state of an application on the master device changes, the master device can directly modify the value of the first variable locally, and simultaneously modify the value of the variable's version identifier. When the device state of an application on a non-master device changes, or when the network state of an application on a non-master device changes, the non-master device, lacking permission to modify the variable value and to prevent other devices from simultaneously modifying the value of the first variable, can first request the master device to lock the first variable, instructing the master device not to modify the value of the first variable based on requests from other non-master devices. The non-master device then sends a notification message to the master device, carrying the value of the first variable. Upon receiving the notification message, the master device can modify the value of the first variable locally according to the notification message. After completing the modification, the master device can notify the non-master device that the variable modification is complete.

[0016] In a second aspect, an apparatus for sharing information is provided, comprising: a determining unit for determining that the code corresponding to a first variable in the source code of an application includes a keyword, the keyword being used to indicate that the first variable is a multi-device shared variable; and a generating unit for generating first target code corresponding to an auxiliary variable associated with the first variable, the auxiliary variable being used to support the sharing of the first variable among multiple devices when the application is running on multiple devices.

[0017] The beneficial effects of the second aspect can be found in the explanation of the first aspect, and will not be repeated here.

[0018] In one possible design, the generation unit is also used to: generate a second target code for the application based on the code corresponding to the first variable and the first target code, wherein the second target code is used to determine the owner device among the multiple devices when the application is running on multiple devices.

[0019] In one possible design, the generation unit is also used to: generate third target code based on the code corresponding to the first variable and the first target code. The third target code is used to read the value of the first variable across multiple devices when the application is running on multiple devices.

[0020] In one possible design, the generation unit is also used to: generate a fourth target code based on the code corresponding to the first variable and the first target code. The fourth target code is used to modify the value of the first variable across multiple devices when the application is running on multiple devices.

[0021] In one possible design, auxiliary variables include variables indicating whether it is a master device, variables indicating the version identifier of the first variable, and variables indicating the sharing mode of the first variable among multiple devices.

[0022] In one possible design, when the auxiliary variable is used to indicate the sharing mode of the first variable among multiple devices, the sharing mode includes a first mode or a second mode; in the first mode, when the first device in the multiple devices modifies the value of the first variable locally on the first device, the first device notifies the other devices in the multiple devices of the event of modifying the value of the first variable; in the second mode, when the second device in the multiple devices modifies the value of the first variable locally on the second device, the second device notifies the owner device in the multiple devices of the event of modifying the value of the first variable, and the other devices in the multiple devices query the value of the first variable from the owner device.

[0023] Thirdly, embodiments of this application provide a computer-readable storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the method of sharing information in the first aspect and any possible design of the first aspect.

[0024] Fourthly, embodiments of this application provide a computer program product that, when run on a computer, causes an electronic device to execute the method of sharing information in the first aspect and any possible design of the first aspect. Attached Figure Description

[0025] Figure 1 This application provides a schematic diagram of a network architecture for multiple devices to share information.

[0026] Figure 2 A schematic diagram illustrating the overall framework of the code development phase of an application provided in this embodiment of the application;

[0027] Figure 3 A schematic diagram illustrating the development process of an information sharing method provided in this application embodiment;

[0028] Figure 4 A schematic diagram illustrating the overall framework of the code development phase of an application provided in this embodiment of the application;

[0029] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0030] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0031] For ease of understanding, the examples provide explanations of some concepts related to the embodiments of this application for reference. As shown below:

[0032] Source code: Software specification code written by developers, which can be used to generate target code, i.e. code that computers can recognize.

[0033] A compiler is a program that can compile a language (usually a high-level language) into another language (usually a low-level language). Compilation is the process of translating source code (usually a high-level language) into target code (usually a low-level language or machine language) that can be directly executed by a computer or virtual machine.

[0034] Target code: refers to the binary code generated by the source code through a compiler that can be directly recognized by the Central Processing Unit (CPU) or virtual machine.

[0035] Executable code: The executable file formed by linking the target code. Source code is relative to both the target code and the executable code.

[0036] Shared variables: also known as multi-device shared variables, shared variables can be used to keep multiple devices synchronized.

[0037] This application addresses scenarios where applications share information across multiple devices or maintain synchronized operation across multiple devices. To address the problem of developers having a heavy workload and prone to errors when coding applications to maintain synchronization across multiple devices, this application provides a method for sharing information. It can automatically generate target code for sharing shared variables across multiple devices based on keywords in the application's shared variables, thereby reducing the developer's coding workload and lowering coding complexity.

[0038] In scenarios where multiple devices share information, these devices may be on the same Wireless Fidelity (WiFi) network or the same local area network (LAN), such as within the same Virtual Private Network (VPN). For these network scenarios, refer to... Figure 1 Multiple devices can include Figure 1 Devices 11, 12, 13, and 14 are listed. One of these four devices is the owner device, while the others can be non-owner devices. The owner device has the highest privileges among the devices. For example, the owner device can store the latest values ​​of shared variables, which non-owner devices can retrieve from the owner device when they need to synchronize shared variables; alternatively, the owner device may have the privilege to directly modify the values ​​of shared variables.

[0039] Among them, the above Figure 1The devices mentioned can be, for example, terminal devices or other network devices. Terminal devices can also be referred to as user equipment (UE), access terminals, user units, user stations, mobile stations, mobile stations, remote stations, remote terminals, mobile devices, user terminals, terminals, wireless communication devices, user agents, or user devices. In the embodiments of this application, the terminal devices can be mobile phones, tablets, computers with wireless transceiver capabilities, virtual reality (VR) terminal devices, augmented reality (AR) terminal devices, wireless terminals in industrial control, wireless terminals in self-driving, wireless terminals in remote medical care, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, terminal devices in 5G networks, or terminal devices in future evolved public land mobile networks (PLMNs), etc. The embodiments of this application do not limit the application scenarios.

[0040] This application can be applied to the code development phase of methods for sharing information between multiple devices before the application runs on multiple devices and maintains information sharing. For example... Figure 2The diagram illustrates the overall framework of this application's code development phase, comprising two parts: writing the application's software specifications (which can also be understood as code language standards) and the compiler generating the application's target code. Unlike existing technologies, in this application, developers can add keywords to shared variables that need to be shared across multiple devices when writing the application's source code. This allows the compiler to automatically generate auxiliary variables associated with the shared variables and target code for synchronizing these shared variables across multiple devices. In existing technologies, auxiliary variables associated with shared variables are also considered source code and need to be written by the developer during the development phase. The synchronization of shared variables across multiple devices (including variable modification and retrieval, determination of the owner device, etc.) also requires the developer to write source code, which is then translated into target code by the compiler. It is understandable that this application only requires developers to write the source code of the shared variables in the software specification. The source code of the auxiliary variables and the synchronization of the shared variables across multiple devices can be automatically generated by the compiler based on the source code of the shared variables. The compiler then generates the target code based on all the source code of the application. This can reduce the workload of developers in writing application code and also reduce the complexity of code development.

[0041] The development process of the information sharing method provided in this application is further explained below, with reference to... Figure 3 The development process of the information sharing method of this application may include:

[0042] 301. Developers write software specifications for applications in the development of software, which include a first variable shared across multiple devices, the code of which includes a keyword indicating that the first variable is a multi-device shared variable.

[0043] The software specifications written by the developers are the source code, which is written by the developers using the software development software. These specifications can also be understood as the language specifications for the application.

[0044] The application in this application is a multi-device sharing application, that is, when the value of the variable of the application is updated on one device, other devices in the multi-device system can keep the multi-device system synchronized, and other devices also update the value of the variable locally.

[0045] For example, if the application is a navigation application, multiple devices in the same network environment will run the navigation application and keep the user's location synchronized.

[0046] Unlike existing technologies, when developers write source code for variables that need to be shared across multiple devices, they can use a keyword to indicate that the current variable needs to be shared across multiple devices. This keyword can have different names, for example, deviceshared.

[0047] For example, taking a certain piece of source code as an example, the way a first variable is declared in the prior art software specification is as follows:

[0048] int myState = 0; / / Identifies the device state.

[0049] The value of the first variable is 0, which indicates a state applied to the device. When the value of 0 changes to other values, it means that the state applied to the device has changed.

[0050] This application indicates that the first variable is a multi-device shared variable by adding the keyword `deviceshared`. For example, the source code of the first variable becomes:

[0051] deviceshared int myState=0; / / The use of deviceshared indicates that this first variable needs to be shared by multiple devices.

[0052] In this way, when the device state identified by the first variable changes on one of the multiple devices, other devices can also share that device state and keep the device states of the multiple devices synchronized.

[0053] It should be noted that the first variable here is merely an example of a variable in the software specification written by the developer for the application. Steps 302-307 below generate the target code corresponding to the first variable. When the software specification includes other variables that need to be shared, steps 302-307 can also be used to generate the target code corresponding to those other variables.

[0054] 302. The compiler determines the code corresponding to the first variable in the application's source code, including keywords.

[0055] Once the developers have completed the application's software documentation, the compiler can be triggered to compile the source code corresponding to the software documentation. Before compiling, the compiler can check whether the source code of the software documentation includes keywords that need to be shared by multiple devices, such as `deviceshared` in step 301. If it is determined that such keywords are included, step 303 can be executed according to the pre-defined compilation framework, that is, to generate the target code related to the variables corresponding to the keyword at runtime.

[0056] 303. The compiler generates the first target code corresponding to the auxiliary variable associated with the first variable. The auxiliary variable is used to support the application running on multiple devices, and the first variable is shared among multiple devices.

[0057] Once developers declare variables in the software documentation that need to be shared across multiple devices using keywords, several auxiliary variables are required to enable this sharing functionality. For example, when the first variable is used to identify the status of a device, auxiliary variables may include variables indicating whether it belongs to the master device (or is called the primary device), variables indicating the version identifier of the first variable, and variables indicating the sharing mode of the first variable across multiple devices.

[0058] For example, if the application's software documentation declares the first variable `myState`, and the corresponding source code is `deviceshared int myState`, then the auxiliary variables can be:

[0059] int shareDeviceHolder=0; / / Whether it is the master device; only one device can be the master device.

[0060] int sharedVarVersion=1; / / Version identifier of a variable shared across multiple devices within the application.

[0061] int shareMode=0; / / The sharing mode for multi-device variables, determined by compiler options or application runtime configuration.

[0062] The auxiliary variable `shareDeviceHolder` is the variable that indicates whether the device is the owner. For example, a value of 0 indicates that the device is not the owner, and a value of 1 indicates that the device is the owner.

[0063] The auxiliary variable `sharedVarVersion` is the variable that indicates the version identifier of the first variable. Each device's application code includes this first variable. To maintain synchronization of the shared variable across multiple devices, the value of the first variable can be modified across different devices. Each time the value of the first variable corresponding to an application on a different device is modified, the value of `sharedVarVersion` for that application is incremented by 1. In other words, `sharedVarVersion` represents the number of times the first variable has been modified within that device's application, or the nth modification. Therefore, when the value of `sharedVarVersion` is highest in the application of the first device in a multi-device setup, it indicates that the device state of that first device—that is, the value of the first variable in that first device's application has been most recently updated—is synchronized with other devices. The values ​​of the first variable in the applications of other devices must be the same as those in the application of the first device.

[0064] The auxiliary variable shareMode can be understood as the sharing mode after the first variable is modified. For example, a value of 0 for shareMode indicates one sharing mode, and a value of 1 for shareMode indicates another sharing mode.

[0065] For example, when an auxiliary variable is used to indicate the sharing mode of the first variable across multiple devices, the sharing mode includes a first mode or a second mode;

[0066] In the first mode, when the first device in a multi-device setup modifies the value of a local variable, it notifies the other devices in the setup of this event. The first device can be understood as any one of the devices in the setup; if the device state of any device's application changes (i.e., the value of the first variable is modified), that device will send a notification to the other devices in the setup to indicate that the value of the first variable has been modified, ensuring that the values ​​of the corresponding first variables on the other devices remain consistent. In this mode, the amount of data communication required for synchronization between the multiple devices is relatively large, data consistency is good, and data access speed is fast.

[0067] In the second mode, when a second device in a multi-device setup modifies the value of a local first variable, it notifies the master device of the modification event. Other devices then query the master device for the latest value of the first variable. In other words, after the value of the first variable for any device in the multi-device setup is modified, that device only notifies the master device of the modification event; other non-master devices need to query the master device for the latest value of the first variable to maintain device synchronization. Although reading the value of the first variable is slower in the second mode, the bandwidth required to read the variable is less.

[0068] The two modes described above are also object code generated by the compiler based on the source code containing the first variable.

[0069] The auxiliary variables of the first variable mentioned above are merely illustrative examples. The auxiliary variables of the first variable may also include other variables, which are not limited in this application.

[0070] 304. The compiler generates the application's second target code based on the code corresponding to the first variable and the first target code. The second target code is used to determine the master device among the multiple devices when the application is running on multiple devices.

[0071] That is, after the compiler generates the first target code corresponding to the auxiliary variables, it still needs to continue generating the relevant code for the implementation of the application's synchronization across multiple devices.

[0072] The second object code in this application can be understood as a rule for determining the master device among multiple devices. For example, this rule could be:

[0073] In a network of interconnected devices, the device that first runs the application can be designated as the owner device, while other devices that do not run the application can be designated as non-owner devices.

[0074] If the master device malfunctions and needs to exit the multi-device connection, the device that joined the network connection earliest among the other devices will be identified as the new master device.

[0075] While the current owner device is operating normally, a non-owner device can request to become the new owner device. The current owner device can grant or deny the request based on its own circumstances. For example, if the application on the current owner device is active (i.e., busy), the current owner device can deny the request to prevent the application from being suspended.

[0076] It is understood that the rules for determining the owner device may include other rules, and this application is only for illustrative purposes.

[0077] 305. The compiler generates third target code based on the code corresponding to the first variable and the first target code. The third target code is used to read the value of the first variable across multiple devices when the application runs on multiple devices.

[0078] After the compiler generates the second object code, it can continue to generate other related code for implementing multi-device synchronous operation. The third object code is used to implement cross-device reading of the value of the first variable under multi-device connection.

[0079] For example, the third target code is used to implement:

[0080] The owner device can directly read the value of the first variable from the owner device's local storage; the value of the first variable stored on the owner device is the most recently updated value.

[0081] For a non-owner device to read the latest value of the first variable, it needs to read it from the owner device first to maintain the device state corresponding to the latest value. For example, if a non-owner device wants to query the latest state of the application on the owner device, it needs to query the value of the first variable on the owner device (when the value of the first variable is updated on other devices, the owner device will be notified, and the owner device stores the latest value of the first variable).

[0082] 306. The compiler generates fourth target code based on the code corresponding to the first variable and the first target code. The fourth target code is used to modify the value of the first variable across multiple devices when the application runs on multiple devices.

[0083] It is understandable that when the device state indicated by the first variable changes, the value of the first variable also changes accordingly.

[0084] The fourth target code is used to implement how the value of the first variable changes when the device state changes.

[0085] For example, when the device state of an application on the owner device changes, or when the network state of an application on the owner device changes, the owner device can directly modify the value of the first variable locally, and at the same time modify the value of the variable's version identifier sharedVarVersion.

[0086] When the device state of an application applied on a non-owner device changes, or when the network state of an application applied on a non-owner device changes, the non-owner device, lacking permission to modify variable values ​​and to prevent other devices from simultaneously modifying the value of the first variable, can first request the owner device to lock the first variable. This instructs the owner device not to modify the value of the first variable based on requests from other non-owner devices. The non-owner device then sends a notification message to the owner device, carrying the value of the first variable. Upon receiving the notification message, the owner device can modify the value of the first variable locally according to the notification message. After modification, the owner device can notify the non-owner device that the variable modification is complete.

[0087] It should be noted that the execution order of steps 305 and 306 can be either step 305 first and then step 306, or step 306 first and then step 305.

[0088] like Figure 4 As shown, steps 303-304 above can also be source code generated by the compiler first. This source code can be understood as the read / write logic and modification logic of the first variable generated based on the first variable, and then the target code is generated by compiling based on this logic. For example, in the read / write logic, when each device in the multi-device array performs a read operation to read the value of the first variable, the device does not read it directly from its local memory first, but first determines whether it is the master device before performing the operation as described above; when each device in the multi-device array performs a write operation to modify the value of the first variable, the device does not modify it directly from its local memory first, but first determines whether it is the master device before performing the operation as described above.

[0089] The target code in step 303 or 304 can also be understood as business code, which includes the read variable function for read operations, the write variable function for user write operations, and the function for modifying variable values, etc.

[0090] It should be noted that the target code generated in steps 304-306 may differ depending on whether it is run with a support library or a virtual machine. Alternatively, it can be understood that these two running modes support different compilation methods, but the logic of the target code obtained under different compilation methods is the same. Specifically, the target code for the support library can be code that can be directly run on the device's CPU, generated from the source code of the first variable and the first target program. This type of code cannot be directly run on a virtual machine. The target code for the virtual machine can be code that can be directly run on a virtual machine.

[0091] 307. The compiler generates executable code based on the first target code, the second target code, the third target code, and the fourth target code.

[0092] The applications that users install on their devices can be understood as executable code downloaded from the network. When a user launches an application on their device, it runs according to the executable code.

[0093] Therefore, this application, during the application development stage (i.e., when developers write the application code), declares that the shared variable can be shared across multiple devices by adding language keywords to the shared variable. This allows the compiler to automatically compile the auxiliary variables related to the shared variable, as well as the target code corresponding to the determination of the owner device related to the shared variable, variable reading, and variable modification. This reduces the workload of developers, lowers the complexity of the code, and thus relatively reduces the probability of errors in the target code.

[0094] It is understood that, in order to achieve the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. An application containing a compiler runs on the electronic device, which can be used to execute the above method embodiments. Based on the algorithmic steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or software-driven manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.

[0095] This embodiment can divide the electronic device into functional modules according to the above method example. For example, each function can be divided into its own functional modules, or two or more functions can be integrated into one processing module. The integrated modules can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0096] When dividing each function into modules according to its corresponding function. Figure 5 A schematic diagram of a possible composition of the electronic device 50 involved in the above embodiments is shown, such as... Figure 5 As shown, the electronic device 50 may include a compiler, which includes a determining unit 501 and a generating unit 502.

[0097] The determining unit 501 can be used to support the electronic device 50 in performing the above-described steps 302, and / or other processes used in the technology described herein.

[0098] The generation unit 502 can be used to support the electronic device 50 in performing the above steps 303 to 307, and / or other processes used in the technology described herein.

[0099] It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.

[0100] The electronic device 50 provided in this embodiment is used to execute the above-described method for sharing information, and thus can achieve the same effect as the above-described implementation method.

[0101] When using integrated units, the electronic device 50 may include a processing module and a storage module. The processing module can be used to control and manage the operations of the electronic device 50, for example, to support the electronic device 50 in executing the steps performed by the determining unit 501 and the generating unit 502. The storage module can be used to support the electronic device 50 in storing program code and data, such as storing code and data corresponding to the implementation of the compiler-generated code of this application.

[0102] The processing module can be a processor or a controller. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module can be a memory. The memory stores instructions and / or code corresponding to the above method embodiments, including compiler instructions, instructions written by developers in the compiler, and instructions automatically generated by the compiler, etc.

[0103] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in this embodiment can be a device having... Figure 6 The electronic device shown has the following structure. Figure 6 Electronic devices may also include transceivers for communicating with other devices. For example... Figure 6The electronic devices shown are personal computers (PCs) or laptops, etc.

[0104] This application also provides an electronic device, including one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, including computer instructions. When the one or more processors execute the computer instructions, the electronic device performs the aforementioned method steps to implement the method for sharing information in the above embodiments.

[0105] Embodiments of this application also provide a computer storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the aforementioned method steps to implement the method for sharing information in the above embodiments.

[0106] Embodiments of this application also provide a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to realize the method of sharing information executed by the electronic device in the above embodiments.

[0107] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to execute the method of sharing information executed by the electronic device in the above method embodiments.

[0108] In this embodiment, the electronic device, computer storage medium, computer program product or chip are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding method provided above, and will not be repeated here.

[0109] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0110] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0111] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0112] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0113] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0114] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for sharing information, characterized in that, include: The code corresponding to the first variable in the application's source code includes a keyword, which is used to indicate that the first variable is a multi-device shared variable; Generate first target code corresponding to an auxiliary variable associated with the first variable, wherein the auxiliary variable is used to support the application running on multiple devices, and the first variable is shared among multiple devices; The auxiliary variables include variables indicating whether it is a master device, variables indicating the version identifier of the first variable, and variables indicating the sharing mode of the first variable among the multiple devices; developers do not need to write source code corresponding to other auxiliary variables associated with the shared variables including the keyword; when the compiler compiles the first target code according to the source code, if it determines that the source code carries the keyword, it generates the first target code of the auxiliary variables associated with the shared variables according to the preset compilation framework.

2. The method according to claim 1, characterized in that, The method further includes: The second target code of the application is generated based on the code corresponding to the first variable and the first target code. The second target code is used to determine the master device among the multiple devices when the application is running on multiple devices.

3. The method according to claim 2, characterized in that, The method further includes: A third target code is generated based on the code corresponding to the first variable and the first target code. The third target code is used to read the value of the first variable across multiple devices when the application is running on multiple devices.

4. The method according to any one of claims 1-3, characterized in that, The method further includes: A fourth target code is generated based on the code corresponding to the first variable and the first target code. The fourth target code is used to modify the value of the first variable across multiple devices when the application is running on multiple devices.

5. The method according to any one of claims 1-3, characterized in that, The auxiliary variable is used to indicate the sharing mode of the first variable among the multiple devices, wherein the sharing mode includes a first mode or a second mode; In the first mode, when the first device in the multi-device setup modifies the value of the first variable locally on the first device, the first device notifies the other devices in the multi-device setup of the event of modifying the value of the first variable. In the second mode, when the second device in the multi-device setup modifies the value of the first variable locally on the second device, the second device notifies the owner device in the multi-device setup of the event of modifying the value of the first variable, and the other devices in the multi-device setup query the value of the first variable from the owner device.

6. A device for sharing information, characterized in that, include: A determining unit is used to determine that the code corresponding to the first variable in the source code of the application includes a keyword, the keyword being used to indicate that the first variable is a multi-device shared variable; A generation unit is used to generate first target code corresponding to an auxiliary variable associated with the first variable, wherein the auxiliary variable is used to support the application running on multiple devices, and the first variable is shared among multiple devices; The auxiliary variables include variables indicating whether it is a master device, variables indicating the version identifier of the first variable, and variables indicating the sharing mode of the first variable among the multiple devices; developers do not need to write source code corresponding to other auxiliary variables associated with the shared variables including the keyword; when the compiler compiles the first target code according to the source code, if it determines that the source code carries the keyword, it generates the first target code of the auxiliary variables associated with the shared variables according to the preset compilation framework.

7. The apparatus according to claim 6, characterized in that, The generation unit is also used for: The second target code of the application is generated based on the code corresponding to the first variable and the first target code. The second target code is used to determine the master device among the multiple devices when the application is running on multiple devices.

8. The apparatus according to claim 7, characterized in that, The generation unit is also used for: A third target code is generated based on the code corresponding to the first variable and the first target code. The third target code is used to read the value of the first variable across multiple devices when the application is running on multiple devices.

9. The apparatus according to any one of claims 6-8, characterized in that, The generation unit is also used for: A fourth target code is generated based on the code corresponding to the first variable and the first target code. The fourth target code is used to modify the value of the first variable across multiple devices when the application is running on multiple devices.

10. The apparatus according to any one of claims 6-8, characterized in that, The auxiliary variable is used to indicate the sharing mode of the first variable among the multiple devices, wherein the sharing mode includes a first mode or a second mode; In the first mode, when the first device in the multi-device setup modifies the value of the first variable locally on the first device, the first device notifies the other devices in the multi-device setup of the event of modifying the value of the first variable. In the second mode, when the second device in the multi-device setup modifies the value of the first variable locally on the second device, the second device notifies the owner device in the multi-device setup of the event of modifying the value of the first variable, and the other devices in the multi-device setup query the value of the first variable from the owner device.

11. A computer-readable storage medium, characterized in that, Includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the method described in any one of claims 1-5.

12. A computer program product, characterized in that, When the computer program product is run on a computer, it causes the electronic device to perform the method described in any one of claims 1-5.