-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththread_class_test.cpp
More file actions
67 lines (58 loc) · 2.17 KB
/
thread_class_test.cpp
File metadata and controls
67 lines (58 loc) · 2.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
#include "thread_class.h"
int main()
{
///*
{
using namespace std;
using namespace test_namespace;
unsigned args = 5;
const unsigned THREAM_SUM = 5;
/// test 0 ... 【故意的】complie error ...
// thread_base *pThread0 = new thread_base(NULL);
// delete pThread0;
/// test 1 ...
// test_thread2* pArray = new test_thread2[THREAM_SUM];
// for (size_t i=0; i < THREAM_SUM; i++)
// ::WaitForSingleObject(pArray[i].handle(), INFINITE);
//
// delete[] pArray;
/// test 2 ...
// auto_ptr<test_thread> pTest1(new test_thread(&args));
// pTest1->resume();/// on-or-off
// if (::WaitForSingleObject(pTest1->handle(), 10000) == WAIT_TIMEOUT)
// std::cout << " The time-out interval 10s elapsed, and the object's state is nonsignaled.\n";
/// test 3 ...
// test_thread2 test2;
// //test2.resume();/// on-or-off
// if (::WaitForSingleObject(test2.handle(), 10000) == WAIT_TIMEOUT)
// std::cout << " The time-out interval 10s elapsed, and the object's state is nonsignaled.\n";
/// test 4 ...
/// 【注】test_thread, test_thread2 线程类不适宜结合有构造参数的std::vector使用,
/// 可能因为std::vector构造函数内部的复制构造过程导致句柄[HANDLE]失效,详细原因可进步深究!
std::vector<test_thread2> thread_vec(5, &args);///or test_thread
std::cout << " " << thread_vec.size() << "\n";
for (size_t i=0; i < thread_vec.size(); i++)
{
::WaitForSingleObject(thread_vec[i].handle(), INFINITE);// ?...
std::cout << "WaitForSingleObject Pass.\n";
}
/// test 5 【注】可能打印出现错乱,属于IO(std::cout)中断操作导致。
// test_thread threads[THREAM_SUM];
// for (size_t i=0; i < THREAM_SUM; i++)
// threads[i].resume();
//
// for (size_t i=0; i < THREAM_SUM; i++)
// ::WaitForSingleObject(threads[i].handle(), INFINITE);
//
// test_thread2 threads2[THREAM_SUM];
// for (size_t i=0; i < THREAM_SUM; i++)
// ::WaitForSingleObject(threads2[i].handle(), INFINITE);
//////////////////////////////////////////////////////////////////////////
std::cout << " all threads are finish !\n";
}
/** = = = = = = = = = =*/
cout << "Hello world!" << endl;
return 0;
}