# 上課問題 # 題目 ### 林子皓 Q1:What are the benefits of multithreading? Responsiveness – may allow continued execution if part of process is blocked, especially important for user interfaces Resource Sharing – threads share resources of process, easier than shared memory or message passing Economy – cheaper than process creation, thread switching lower overhead than context switching Scalability – process can take advantage of multiprocessor architectures Q2:Multicore or multiprocessor systems putting pressure on programmers, challenges include: Dividing activities Balance Data splitting Data dependency Testing and debugging ### 楊秉沅 Q1:Which of the following statement is TRUE ? (A)In the Many-to-One multithreading model,if a thread makes a blocking system call,a part of the process will stay blocked, with the rest running (B)The One-to-One multithreading model multiplexes map many user-level threads to a smaller or equal number of kernel threads. \(C)The multi-threading model has the following types, One-to-One,Many-to-One,One-to-Many (D)one-to-one model allows multiple threads to run in parallel on multiprocessors. A1:(D) Q2:Which of the following statement is TRUE ? (A)pthread_create() in Pthreads and CreateThread() in Windows are use to create thread (B)pthread_wait() in Pthreads and WaitForSingleObject() in Windows are use to wait the thread to finish \(C)pthread_exit() in Pthreads and ExitHandle() in Windows are use to exit (D)Pthreads and Win32 are only provided kernel-level A2:(A) Q3:Which of the following statement is TRUE ? (A)Deferred cancellation terminates the target thread immediately. (B)If the application execute fork() then exec() immediately,will duplicate all of the threads in process. \(C)User-defined signal handler cannot override default handler (D)One of the advantages of thread pools is can control the number of threads. A3:(D) ### 王尚鵬 Q1:What are the 2 ways to create a thread in Java? A1:By implementing Runnable interface or Extend Thread class. Q2:Which of the following statement is NOT TRUE ? (A) ETHREAD, KTHREAD, TEB are linked together with pointer. (B) Thread creation is done through clone() system call in Linux System. \(C) ETHREAD, KTHREAD, TEB are all in the kernel space. (D) The register set, stacks, and private storage area are known as the context of the thread. A2: C is not true. ETHREAD and KTHREAD are in kernel space, TEB is in user space. ### 楊閔恩 Q1:Where should a signal be delivered for multi-threaded(should contain 4 answers)? 1. Deliver the signal to the thread to which the signal applies 2. Deliver the signal to every thread in the process 3. Deliver the signal to certain threads in the process 4. Assign a specific thread to receive all signals for the Process Q2:Why use thread pool? What are the benefits? 1. Usually slightly faster to service a request with an existing thread than create a new thread 2. Allows the number of threads in the application(s) to be bound to the size of the pool. 3. Separating task to be performed from mechanics of creating task allows different strategies for running task