| 35 | } |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | // create a thread that will call thread_1(45.6) |
| 40 | thread_function t1(thread_1,45.6); |
| 41 | // wait for the t1 thread to end |
| 42 | t1.wait(); |
| 43 | |
| 44 | |
| 45 | // create a thread that will call thread_1(9.999) |
| 46 | thread_function t2(thread_1,9.999); |
| 47 | // wait for the t2 thread to end |
| 48 | t2.wait(); |
| 49 | |
| 50 | |
| 51 | // create a thread that will call thread_2() |
| 52 | thread_function t3(thread_2); |
| 53 | |
| 54 | |
| 55 | // Note that we can also use the ref() function to pass a variable |
| 56 | // to a thread by reference. For example, the thread below adds |
| 57 | // one to val. |
| 58 | double val = 2; |
| 59 | thread_function t4(thread_increment, dlib::ref(val)); |
| 60 | t4.wait(); // wait for t4 to finish before printing val. |
| 61 | // Print val. It will now have a value of 3. |
| 62 | cout << "val: " << val << endl; |
| 63 | |
| 64 | |
| 65 | |
| 66 | // At this point we will automatically wait for t3 to end because |
| 67 | // the destructor for thread_function objects always wait for their |
| 68 | // thread to terminate. |
| 69 | } |
| 70 | |
| 71 | |