To start a thread using the C++ standard library, which syntax should be utilized?
std::thread newThread(function_name)
newThread is a variable name and this uses the std::thread class's constructorm, which implicitly starts a new thread.
2.
질문 2Detaching a thread makes it execute completely independent of the current program, even if the program is stopped?
3.
질문 3Using the C++ standard mutex library, fill in the blank to keep multiple. threads from accessing the same critical code section but guarantee code execution.
std::mutex._____ critical code section std::mutex._____
lock(), unlock()
You are locking a critical section of code and then unlocking it after you have run the critical code. Note that using try_lock does not guarantee the critical section of code will be run, just that the thread will continue to execute some code.
Do not guarantee access will not cause a race condition.
One of the main purposes of atomic variables is that they synchronize access to variables, which implicitly guarantees that race conditions will not occur with that atomic variable.
5.
질문 5_______ are wrappers around the results of an operation and ________ synchronize access to these results.
Promises, futures
Promises are what are returned so that code can determine how it wants to handle waiting or not for a result, while a future is the mechanism for the synchronization.
'Coursera' 카테고리의 다른 글
[GPU programming] Multidimensional Data and Computation on the GPU Quiz (0) | 2022.07.18 |
---|---|
[GPU programming] GPU Programming Quiz (0) | 2022.06.27 |
[GPU programming] Nvidia Software and Hardware Quiz (0) | 2022.06.26 |
[GPU programming] Python 3 Parallel Programming Quiz (0) | 2022.06.22 |
[GPU programming] thread in python (0) | 2022.06.22 |