diff --git a/OAT.xml b/OAT.xml index ec61e645a36fed813aae5a661de7263ab42adea8..6b94ea812aa1e444b6b52337bf0eec17d79dcc19 100644 --- a/OAT.xml +++ b/OAT.xml @@ -165,6 +165,10 @@ Note:If the text contains special characters, please escape them according to th + + + + @@ -2139,6 +2143,11 @@ Note:If the text contains special characters, please escape them according to th + + + + + @@ -2219,6 +2228,11 @@ Note:If the text contains special characters, please escape them according to th + + + + + diff --git a/code/ArkTS1.2/ParallelSample/.gitignore b/code/ArkTS1.2/ParallelSample/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/AppScope/app.json5 b/code/ArkTS1.2/ParallelSample/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ee07d3be2d5ef3d5e3de54614455ff2c598f0183 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.samples.parallelTest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/ArkTS1.2/ParallelSample/AppScope/resources/base/element/string.json b/code/ArkTS1.2/ParallelSample/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..89809692052f1e629b3f0e1ddbed4521c3d6932a --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "parallelTest" + } + ] +} diff --git a/code/ArkTS1.2/ParallelSample/AppScope/resources/base/media/app_icon.png b/code/ArkTS1.2/ParallelSample/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/ArkTS1.2/ParallelSample/AppScope/resources/base/media/app_icon.png differ diff --git a/code/ArkTS1.2/ParallelSample/build-profile.json5 b/code/ArkTS1.2/ParallelSample/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7178fe08b386249b64b2c1afbd1e9844aa959548 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "arkTSVersion": "1.2", + "compatibleSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/code-linter.json5 b/code/ArkTS1.2/ParallelSample/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/.gitignore b/code/ArkTS1.2/ParallelSample/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/build-profile.json5 b/code/ArkTS1.2/ParallelSample/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/hvigorfile.ts b/code/ArkTS1.2/ParallelSample/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/ArkTS1.2/ParallelSample/entry/obfuscation-rules.txt b/code/ArkTS1.2/ParallelSample/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/oh-package.json5 b/code/ArkTS1.2/ParallelSample/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/ets/entryability/EntryAbility.ets b/code/ArkTS1.2/ParallelSample/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d205c00999b495e390eb8582f3dec20cc547d5fc --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,54 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import { BusinessError } from '@ohos.base' +import hilog from '@ohos.hilog' + +class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', 'EntryAbility onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + hilog.info(0x0000, 'testTag', 'EntryAbility onWindowStageCreate'); + try { + windowStage.loadContent('pages/Index', (err: BusinessError): void => { + hilog.info(0x0000, 'testTag', 'loadContent entering'); + if (err.code) { + hilog.info(0x0000, 'testTag', 'loadContent error'); + return; + } + hilog.info(0x0000, 'testTag', 'loadContent ok'); + }); + } catch (e: Error) { + hilog.info(0x0000, 'testTag', 'loadContent catch error:-----------' + e.message); + } + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/ets/pages/Index.ets b/code/ArkTS1.2/ParallelSample/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c1f6504dd6c3d265aec0e1948121cc9fe4349d4b --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,499 @@ +/** + * + * Copyright (c) 2025 Huawei Device Co., Ltd. + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice,this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, + * + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import { + memo, + __memo_context_type, + __memo_id_type +} from "@ohos.arkui.stateManagement" // should be insert by ui-plugins +import { + Text, + TextAttribute, + Column, + Component, + Button, + ButtonAttribute, + ClickEvent, + UserView, + Row, +} from "@ohos.arkui.component" // TextAttribute should be insert by ui-plugins +import { + State, + StateDecoratedVariable, + MutableState, + stateOf, + observableProxy +} from "@ohos.arkui.stateManagement" // should be insert by ui-plugins +import hilog from '@ohos.hilog' +import fs from '@ohos.file.fs' + +let lockName = 'isAvailableLock'; +let lockTest = AsyncLock.request(lockName); +let lockTest2 = new AsyncLock(); +let lock = new AsyncLock(); +let lock2 = new AsyncLock(); +let lock3 = new AsyncLock(); +let lockFile = new AsyncLock(); +let mapTest: Map = new Map(); +let lockTest3 = new AsyncLock(); +let num = 0; + +function createFileTest(fileName: string, context: string): void { + try { + let res = fs.accessSync(fileName); + let file = fs.openSync(fileName, 0o100 | 0o2) + let byteNumber = fs.writeSync(file.fd, context) + fs.closeSync(file.fd) + } catch (e) { + hilog.error(0x0000, 'testTag', 'openSync fail' + `${e}`); + } +} + +@Component +struct MyStateSample { + @State stringTest1LockSame: string = "预期结果"; + @State stringTest1Unlock: string = "预期结果"; + @State messageString: string = "加锁"; + @State messageStringUnlock: string = "不加锁"; + @State mapString: string = "预期结果"; + messageStringTmp: string = "预期结果"; + messageStringTmpUnlock: string = "预期结果"; + stringTest1TmpLockSame: string = "预期结果"; + stringTest1TmpUnlock: string = "预期结果"; + @State stringTest2: string = "预期结果"; + @State stringFile: string = "预期结果"; + @State priorityString: string = "预期结果"; + @State addString: string = "预期结果 "; + @State taskGroupString: string = "预期结果 "; + + async readFile(fileName: string): Promise { + await lockFile.lockAsync(() => { + try { + let file = fs.openSync(fileName, 0o100 | 0o2) + let result = fs.readTextSync(fileName) + hilog.info(0x0000, 'testTag', 'foo file result ' + `${result}`); + this.stringFile = JSON.stringify(result); + fs.closeSync(file.fd) + } catch (e) { + hilog.error(0x0000, 'testTag', 'openSync fail' + `${e}`); + } + }); + } + + async fooTest(): Promise { + let p1 = await lockTest.lockAsync(() => { + for (let i = 0; i < 25; ++i) { + this.stringTest1TmpLockSame += "1"; + } + }); + this.stringTest1LockSame = this.stringTest1TmpLockSame + } + + async fooTest2(): Promise { + let p2 = await lockTest.lockAsync(() => { + for (let i = 0; i < 25; ++i) { + this.stringTest1TmpLockSame += "2"; + } + }); + this.stringTest1LockSame = this.stringTest1TmpLockSame; + } + + async fooTest3(): Promise { + let p2 = await lockTest.lockAsync(() => { + for (let i = 0; i < 25; ++i) { + this.stringTest1TmpLockSame += "3"; + } + }); + this.stringTest1LockSame = this.stringTest1TmpLockSame; + } + + fooTestUnlock(): void { + for (let i = 0; i < 25; ++i) { + this.stringTest1TmpUnlock += "1"; + } + this.stringTest1Unlock = this.stringTest1TmpUnlock; + } + + fooTestUnlock2(): void { + for (let i = 0; i < 25; ++i) { + this.stringTest1TmpUnlock += "2"; + } + this.stringTest1Unlock = this.stringTest1TmpUnlock; + } + + fooTestUnlock3(): void { + for (let i = 0; i < 25; ++i) { + this.stringTest1TmpUnlock += "3"; + } + this.stringTest1Unlock = this.stringTest1TmpUnlock; + } + + foo(s: string): void { + lock.lockAsync(() => { + for (let i = 0; i < 25; ++i) { + this.messageStringTmp += s; + } + }) + } + + fooUnLock(s: string): void { + for (let i = 0; i < 50; ++i) { + this.messageStringTmpUnlock += s; + } + } + + fooMapTest(): void { + lockTest3.lockAsync(() => { + for (let i = 0; i < 100; ++i) { + mapTest.set(i, "num " + i); + } + }); + } + + fooMapTest2(): void { + lockTest3.lockAsync(() => { + for (let i = 0; i < 50; ++i) { + if (mapTest.has(i)) { + mapTest.delete(i); + } + } + }); + } + + add(num1: int, num2: int): int { + return num1 + num2; + } + + concurrentFuncAdd() { + const task = new taskpool.Task(this.add, 2, 10) + taskpool.execute(task).then((value: NullishType) => { + hilog.error(0x0000, 'testTag', 'taskpool ' + value); + this.addString += JSON.stringify(value); + }); + } + + args(args: int): int { + return args; + } + + taskTest() { + let taskGroup1: taskpool.TaskGroup = new taskpool.TaskGroup(); + taskGroup1.addTask(this.args, 10); // 10: test number + taskGroup1.addTask(this.args, 20); // 20: test number + taskGroup1.addTask(this.args, 30); // 30: test number + + let taskGroup2: taskpool.TaskGroup = new taskpool.TaskGroup(); + let task1: taskpool.Task = new taskpool.Task(this.args, 100); // 100: test number + let task2: taskpool.Task = new taskpool.Task(this.args, 200); // 200: test number + let task3: taskpool.Task = new taskpool.Task(this.args, 300); // 300: test number + taskGroup2.addTask(task1); + taskGroup2.addTask(task2); + taskGroup2.addTask(task3); + + taskpool.execute(taskGroup2).then((res: Array) => { + hilog.error(0x0000, 'testTag', 'openSync fail' + res); + this.taskGroupString += JSON.stringify(res); + }); + + taskpool.execute(taskGroup1).then((res: Array) => { + hilog.error(0x0000, 'testTag', 'openSync fail' + res); + this.taskGroupString += JSON.stringify(res); + }); + } + + priorityLOW() { + this.priorityString += "低" + } + + priorityHIGH() { + this.priorityString += "高" + } + + priorityMEDIUM() { + this.priorityString += "中" + } + + concurrentFunc() { + for (let i = 0; i < 10; ++i) { + const task = new taskpool.Task(this.priorityHIGH) + const task2 = new taskpool.Task(this.priorityMEDIUM) + const task3 = new taskpool.Task(this.priorityLOW) + taskpool.execute(task, taskpool.Priority.HIGH).then((value: NullishType) => { + hilog.error(0x0000, 'testTag', 'taskpool ' + this.priorityString); + }); + taskpool.execute(task2, taskpool.Priority.MEDIUM).then((value: NullishType) => { + hilog.error(0x0000, 'testTag', 'taskpool ' + this.priorityString); + }); + taskpool.execute(task3, taskpool.Priority.LOW).then((value: NullishType) => { + hilog.error(0x0000, 'testTag', 'taskpool ' + this.priorityString); + }); + } + } + + build() { + Column() { + Column() { + Text("-------------------EAWorker------------------").width("100%") + Button("EAWorker-不同线程共同操作一个函数-加锁") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let eaw3: EAWorker = new EAWorker(true); + eaw.run(this.foo, "&"); + eaw2.run(this.foo, "*"); + eaw3.run(this.foo, "@"); + eaw.join() + eaw2.join() + eaw3.join() + setTimeout(() => { + hilog.info(0x0000, 'testTag', 'messageString' + this.messageStringTmp); + this.messageString = this.messageStringTmp; + this.messageStringTmp = " " + }, 100) + + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:不会出现交替打印的问题").height(50) + Text(this.messageString).width("90%") + } + + Button("EAWorker-不同线程共同操作一个函数-不加锁") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let eaw3: EAWorker = new EAWorker(true); + eaw.run(this.fooUnLock, "&"); + eaw2.run(this.fooUnLock, "*"); + eaw3.run(this.fooUnLock, "@"); + eaw.join() + eaw2.join() + eaw3.join() + setTimeout(() => { + this.messageStringUnlock = this.messageStringTmpUnlock; + this.messageStringTmpUnlock = " " + }, 100) + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:资源竞争,可能会出现交替打印").height(50) + Text(this.messageStringUnlock).width("90%") + } + }.height(200) + + Column() { + Button("EAWorker-不同线程操作不同函数-加锁") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let eaw3: EAWorker = new EAWorker(true); + eaw.run(this.fooTest) + eaw2.run(this.fooTest2) + eaw3.run(this.fooTest3) + eaw.join() + eaw2.join() + eaw3.join() + this.stringTest1TmpLockSame = " " + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:不会出现交替打印的问题-使用锁").height(50) + Text(this.stringTest1LockSame).width("90%") + } + }.height(200) + + Column() { + Button("EAWorker-不同线程操作不同函数-不加锁") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let eaw3: EAWorker = new EAWorker(true); + eaw.run(this.fooTestUnlock) + eaw2.run(this.fooTestUnlock2) + eaw3.run(this.fooTestUnlock3) + eaw.join() + eaw2.join() + eaw3.join() + this.stringTest1TmpUnlock = " " + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:会出现交替打印的问题-不使用锁").height(50) + Text(this.stringTest1Unlock).width("90%") + } + }.height(200) + + Column() { + Button("EAWorker-不同线程共享一个容器") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let job = eaw.run(this.fooMapTest) + let job2 = eaw2.run(this.fooMapTest2) + eaw.join() + eaw2.join() + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:一个线程让map插入100个数据 另一个线程让map删除50个数据,并且map大小应为50,目前EAWorker子线程控制不了时序,可能会出现100(先删除空map,后加100数据) ") + .height(50) + Text(this.mapString).width("90%") + } + }.height(200) + + Column() { + Button("EAWorker-不同线程操作不同函数-不加锁") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let eaw3: EAWorker = new EAWorker(true); + eaw.run(this.fooTestUnlock) + eaw2.run(this.fooTestUnlock2) + eaw3.run(this.fooTestUnlock3) + eaw.join() + eaw2.join() + eaw3.join() + this.stringTest1TmpUnlock = " " + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:会出现交替打印的问题-不使用锁").height(50) + Text(this.stringTest1Unlock).width("90%") + } + }.height(200) + + Column() { + Button("EAWorker-不同线程共享一个容器") + .onClick((e: ClickEvent) => { + let eaw: EAWorker = new EAWorker(true); + let eaw2: EAWorker = new EAWorker(true); + let job = eaw.run(this.fooMapTest) + let job2 = eaw2.run(this.fooMapTest2) + eaw.join() + eaw2.join() + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:一个线程让map插入100个数据 另一个线程让map删除50个数据,并且map大小应为50,目前EAWorker子线程控制不了时序,可能会出现100(先删除空map,后加100数据) ") + .height(50) + Text(this.mapString).width("90%") + } + }.height(200) + + Column() { + Button("EAWorker-不同线程读写同一个文件") + .onClick((e: ClickEvent) => { + hilog.info(0x0000, 'testTag', 'On Click'); + let path: string = "/data/storage/el2/base/haps/entry/files/test.txt"; + let str: string = "com.samples.EAWorker successfully launched"; + createFileTest(path, str); + let eaw: EAWorker = new EAWorker(true); + eaw.run(this.readFile, path); + eaw.join() + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:一个线程在文件写入文本,另一个线程从文件中读取文本").height(50) + Text(this.stringFile).width("90%") + } + }.height(200) + + Text("-------------------taskPool------------------").width("100%") + Column() { + Button("taskPool-执行一组有关联的任务") + .onClick((e: ClickEvent) => { + hilog.info(0x0000, 'testTag', 'On Click'); + this.taskTest(); + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:任务组中任务全部执行完成后,结果数组统一返回").height(50) + Text(this.taskGroupString).width("90%") + } + }.height(200) + + Column() { + Button("taskPool-任务优先级") + .onClick((e: ClickEvent) => { + this.concurrentFunc(); + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:创建实例可以给第二个参数设置权重,假设有两个多线程任务,可以决定优先执行那一个多线程任务") + .height(50) + Text(this.priorityString).width("90%") + } + }.height(200) + + Column() { + Button("taskPool-计算两数之和") + .onClick((e: ClickEvent) => { + hilog.info(0x0000, 'testTag', 'On Click'); + this.concurrentFuncAdd(); + }) + .borderRadius(8) + .backgroundColor(0x317aff) + .width("80%") + Column() { + Text("说明:输入2和10输出 12") + .height(50) + Text(this.addString).width("90%") + } + }.height(200) + } + } +} + +export class ComExampleTrivialApplication extends UserView { + getBuilder() { + hilog.info(0x0000, 'testTag', 'getBuilder'); + let wrapper = @memo() =>{ + hilog.info(0x0000, 'testTag', 'MyStateSample'); + MyStateSample(undefined) + } + return wrapper + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/module.json5 b/code/ArkTS1.2/ParallelSample/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..de78b5cae3b2ba99788048311e5d0cd34d075039 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/module.json5 @@ -0,0 +1,38 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/color.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/float.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/string.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/background.png b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/background.png differ diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/foreground.png b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/layered_image.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/startIcon.png b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/profile/backup_config.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/profile/main_pages.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/ArkTS1.2/ParallelSample/entry/src/main/resources/dark/element/color.json b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/ArkTS1.2/ParallelSample/hvigor/hvigor-config.json5 b/code/ArkTS1.2/ParallelSample/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a9b16a8a74bd1e7b243bf7da0307d931f6574975 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/hvigor/hvigor-config.json5 @@ -0,0 +1,23 @@ +{ + "modelVersion": "5.0.2", + "dependencies": { + "@ohos/hvigor-ohos-online-sign-plugin": "4.0.2" + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/ArkTS1.2/ParallelSample/hvigorfile.ts b/code/ArkTS1.2/ParallelSample/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/ArkTS1.2/ParallelSample/oh-package.json5 b/code/ArkTS1.2/ParallelSample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c36c086ae807ea710acd9e480cb6cc1d18bd011 --- /dev/null +++ b/code/ArkTS1.2/ParallelSample/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.2", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +}