You are writing a method that returns an ArrayList named al. You need to ensure that changes to
the ArrayList are performed in a thread-safe manner. Which code segment should you use?
A. ArrayList^ al = gcnew ArrayList();lock (al->SyncRoot){
return al;}
B. ArrayList^ al = gcnew ArrayList();lock (al->SyncRoot.GetType()){
return al;}
C. ArrayList^ al = gcnew ArrayList();Monitor::Enter(al);Monitor::Exit(al);return al;
D. ArrayList^ al = gcnew ArrayList();ArrayList^ sync_al = ArrayList::Synchronized(al);return
sync_al;
Answer: D
the ArrayList are performed in a thread-safe manner. Which code segment should you use?
A. ArrayList^ al = gcnew ArrayList();lock (al->SyncRoot){
return al;}
B. ArrayList^ al = gcnew ArrayList();lock (al->SyncRoot.GetType()){
return al;}
C. ArrayList^ al = gcnew ArrayList();Monitor::Enter(al);Monitor::Exit(al);return al;
D. ArrayList^ al = gcnew ArrayList();ArrayList^ sync_al = ArrayList::Synchronized(al);return
sync_al;
Answer: D
No comments:
Post a Comment