1# CommonLibrary Subsystem Changelog
2
3## cl.commonlibrary.1 Behavior for the Task Pool to Transfer Sendable Data Is Changed
4
5**Access Level**
6
7Other
8
9**Change Reason**
10
11The task pool is used to execute concurrent tasks. If Sendable data is directly returned in a call or the **sendData** API is called for data transmission, the default transmission mode of the Sendable data is changed from clone to shared. This change is because the data is seldom used after the task in the task pool is executed.
12
13**Change Impact**
14
15This change is a non-compatible change.
16
17Before the change, when **taskpool.Task.sendData** of API version 11 is used to send or directly return Sendable data, one copy is made by default.
18
19After the change, Sendable data is shared in this scenario. If the data is modified in the host thread, the subthread gets notified. However, the task pool is executed by task. There is a low probability that simultaneous operations are performed on the same object, and the impact of subsequent data changes on the task pool is controllable.
20
21In the following code, the printed value may be 100 or changed to 200 by the subthread:
22
23```
24import { taskpool } from '@kit.ArkTS'
25@Sendable
26class A {
27    num: number = 100
28}
29@Concurrent
30async function foo(a: A) {
31    taskpool.Task.sendData(a)
32    a.num = 200
33}
34let a: A = new A()
35let task = new taskpool.Task(foo, a)
36task.onReceiveData((val: A) => {
37    console.log("num: " + val.num)
38})
39```
40
41**Start API Level**
42
43API version 11
44
45**Change Since**
46
47OpenHarmony SDK 5.0.0.18
48
49**Key API/Component Changes**
50
51N/A
52
53**Adaptation Guide**
54
55If **sendData** is not executed in the task pool or the read and write operations on the same attribute are performed by two independent threads after data is returned, no adaptation is required.
56
57If **sendData** is executed in the task pool or the host thread and its subthread read and write the same attribute after data is returned, a lock must be used (imported from @arkts.utils).
58
59Current code:
60
61```
62import { taskpool } from '@kit.ArkTS'
63@Sendable
64class A {
65    num: number = 100
66}
67@Concurrent
68async function foo(a: A) {
69    taskpool.Task.sendData(a)
70    a.num = 200
71}
72let a: A = new A()
73let task = new taskpool.Task(foo, a)
74task.onReceiveData((val: A) => {
75    console.log("num: " + val.num)
76})
77```
78To ensure the thread safety of the **num** domain of class A, synchronization protection is required. The recommended code snippet is as follows:
79```
80import { taskpool } from '@kit.ArkTS'
81@Sendable
82class A {
83    num: number = 100
84    async setNum(num: number) {
85        // add lock here
86        this.num = num
87    }
88    async getNum(): Promise<number> {
89        // add lock here
90        return this.num
91    }
92}
93@Concurrent
94async function foo(a: A) {
95    taskpool.Task.sendData(a)
96    a.setNum(200)
97}
98let a: A = new A()
99let task = new taskpool.Task(foo, a)
100task.onReceiveData((val: A) => {
101    console.log("num: " + val.getNum())
102})
103```
104
105
106## cl.commonlibrary.2 taskId in taskInfos Obtained by Calling taskpool.getTaskPoolInfo Is Changed from BigInt to Number
107
108**Access Level**
109
110Other
111
112**Change Reason**
113
114**taskId** of the number type is sufficient for use.
115
116**Change Impact**
117
118This change is a non-compatible change.
119
120Before the change, the **taskId** type is BigInt.
121
122After the change, the **taskId** type is number. **taskId** is a member of **TaskInfo** in the **TaskPoolInfo** class obtained through **taskpool.getTaskPoolInfo**. The change of the member type does not affect other attributes obtained using **taskpool.getTaskPoolInfo**. The change has little impact on developers.
123
124Current code:
125```ts
126import { taskpool } from '@kit.ArkTS'
127
128@Concurrent
129function delay(): void {
130  let start: number = new Date().getTime();
131  while (new Date().getTime() - start < 500) {
132    continue;
133  }
134}
135
136let task1: taskpool.Task = new taskpool.Task(delay);
137let task2: taskpool.Task = new taskpool.Task(delay);
138let task3: taskpool.Task = new taskpool.Task(delay);
139taskpool.execute(task1, taskpool.Priority.LOW)
140taskpool.execute(task2, taskpool.Priority.MEDIUM)
141taskpool.execute(task3, taskpool.Priority.HIGH)
142let start: number = new Date().getTime();
143while (new Date().getTime() - start < 1000) {
144  continue;
145}
146let taskpoolInfo: taskpool.TaskPoolInfo = taskpool.getTaskPoolInfo();
147let taskId: number = 0;
148let taskIS = Array.from(taskpoolInfo.taskInfos)
149for(let taskInfo of taskIS) {
150  taskId = taskInfo.taskId;
151  console.info("taskpool---taskId is:" + taskId);
152}
153```
154
155**Start API Level**
156
157API version 11
158
159**Change Since**
160
161OpenHarmony SDK 5.0.0.18
162
163**Key API/Component Changes**
164
165taskpool.getTaskPoolInfo
166
167**Adaptation Guide**
168
169Define the **taskId** type as number.
170