首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

使用 System V Semaphores API 实现 POSIX Semaphore API-2

使用 System V Semaphores API 实现 POSIX Semaphore API-2

清单 7. 使用了现有 POSIX API 的测试应用程序的输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
bash-3.2# ./test1original

Thread no 0 id = 258 created
Threadid  id =258(ThreadFunction1), locked and incrementing the count  
Count (ThreadFunction1) = 1
Thread no 1 id = 515 created
Thread no 2 id = 772 created
Thread no 3 id = 1029 created
Thread no 4 id = 1286 created
Thread id 1029 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread no 5 id = 1543 created
Thread no 6 id = 1800 created
Thread id 1800 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread no 7 id = 2057 created
Thread no 8 id = 2314 created
Thread no 9 id = 2571 created
Thread id 2571 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread 258 going to release lock
Thread id = 515(ThreadFunction2) , locked and incrementing the count   
Count (ThreadFunction2) = 2
Thread id 515 going to release lock
Thread id = 772(ThreadFunction2) , locked and incrementing the count   
Count (ThreadFunction2) = 3
Thread id 772 going to release lock
Thread id = 1286(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 4
Thread id 1286 going to release lock
Thread id = 1543(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 5
Thread id 1543 going to release lock
Thread id = 2057(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 6
Thread id 2057 going to release lock
Thread id = 2314(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 7
Thread id 2314 going to release lock
All threads joined, Final count = 7
bash-3.2#




这两个应用程序在 AIX 内有相同的输出。
案例 2 - 利用通过 System V 实现的 semaphore APIs 在 z/OS 上测试应用程序我们用相同的测试应用程序在 z/OS 内进行构建并测试了使用 System V semaphore 实现的 semaphore 文件。而在 AIX 上,我们还运行了另一个使用了已经可用的 POSIX APIS 的测试应用程序,并对输出进行了比较。
如果 z/OS 上的测试结果和 AIX 上的测试结果相同,那么您就可以放心地得出结论:利用了 System V semaphore API 的 POSIX semaphore 实现运行得很好。
显示了相同的测试应用程序(比如在 AIX 内)在 z/OS 内的输出:
清单 8. 使用了 SYTEM V semaphore API 的测试应用程序输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
STLAB60:../finalCode:> ./test1sys5

Thread no 0 id = 542160384 created
Threadid  id =542160384(ThreadFunction1), locked and incrementing the count
Thread no 1 id = 542195200 created      Count (ThreadFunction1) = 1
Thread no 2 id = 542199552 created
Thread no 3 id = 542203904 created
Thread no 4 id = 542208256 created
Thread no 5 id = 542212608 created
Thread no 6 id = 542216960 created
Thread no 7 id = 542221312 created
Thread no 8 id = 542225664 created
Thread no 9 id = 542230016 created
Thread id 542216960 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread id 542230016 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread id 542203904 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread 542160384 going to release lock
Thread id = 542195200(ThreadFunction2) , locked and incrementing the count     
Count (ThreadFunction2) = 2
Thread id 542195200 going to release lock
Thread id = 542199552(ThreadFunction2) , locked and incrementing the count     
Count (ThreadFunction2) = 3
Thread id 542199552 going to release lock
Thread id = 542221312(ThreadFunction2) , locked and incrementing the count     
Count (ThreadFunction2) = 4
Thread id 542221312 going to release lock
Thread id = 542225664(ThreadFunction2) , locked and incrementing the count     
Count (ThreadFunction2) = 5
Thread id 542225664 going to release lock
Thread id = 542208256(ThreadFunction2) , locked and incrementing the count     
Count (ThreadFunction2) = 6
Thread id 542208256 going to release lock
Thread id = 542212608(ThreadFunction2) , locked and incrementing the count     
Count (ThreadFunction2) = 7
Thread id 542212608 going to release lock
All threads joined, Final count = 7




显示了使用了已经可用的 POSIX API 的测试应用程序在 AIX 上的输出:
清单 9. 使用了已经可用的 POSIX API 的测试应用程序输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
bash-3.2# ./test1original

Thread no 0 id = 258 created
Threadid  id =258(ThreadFunction1), locked and incrementing the count  
Count (ThreadFunction1) = 1
Thread no 1 id = 515 created
Thread no 2 id = 772 created
Thread no 3 id = 1029 created
Thread no 4 id = 1286 created
Thread id 1029 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread no 5 id = 1543 created
Thread no 6 id = 1800 created
Thread id 1800 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread no 7 id = 2057 created
Thread no 8 id = 2314 created
Thread no 9 id = 2571 created
Thread id 2571 is in ThreadFunction1, semaphore is already locked and not waiting.
Hence will not increment the counter
Thread 258 going to release lock
Thread id = 515(ThreadFunction2) , locked and incrementing the count   
Count (ThreadFunction2) = 2
Thread id 515 going to release lock
Thread id = 772(ThreadFunction2) , locked and incrementing the count   
Count (ThreadFunction2) = 3
Thread id 772 going to release lock
Thread id = 1286(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 4
Thread id 1286 going to release lock
Thread id = 1543(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 5
Thread id 1543 going to release lock
Thread id = 2057(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 6
Thread id 2057 going to release lock
Thread id = 2314(ThreadFunction2) , locked and incrementing the count  
Count (ThreadFunction2) = 7
Thread id 2314 going to release lock
All threads joined, Final count = 7
bash-3.2#




从结果可以看出,测试应用程序在 z/OS 和 AIX 上具有相同的行为。
返回列表