Coursera

[GPU programming] c++ Parallel Programming Quiz

star.candy 2022. 6. 23. 23:37
질문 1

T​o start a thread using the C++ standard library, which syntax should be utilized?

s​td::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

D​etaching a thread makes it execute completely independent of the current program, even if the program is stopped?

False
 
Detach still keeps the thread in the current process and therefor is killed when the program is stopped, if the thread is still running.
질문 3

U​sing the C++ standard mutex library, fill in the blank to keep multiple. threads from accessing the same critical code section but guarantee code execution.

s​td::mutex._____ critical code section std::mutex._____

l​ock(), 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.

D​o 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

_​______ are wrappers around the results of an operation and ________ synchronize access to these results.

P​romises, 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.