A と B では、どちらが優れているか、または速いですか?
std::deque<Myclass> queue;
... // do something
std::size_t size = 0;
... // create n threads, one push queue and others pop queue.
// a thread do below
#ifdef A
pthread_rwlock_wrlock(&rwlock);
queue.push_front(myobj);
size = queue.size();
pthread_rwlock_unlock(&rwlock);
#endif
#ifdef B
pthread_rwlock_wrlock(&rwlock);
queue.push_front(myobj);
pthread_rwlock_unlock(&rwlock);
// if there is some operation,
// I think this B is better,
// because I should get the newest size.
pthread_rwlock_rdlock(&rwlock);
size = queue.size();
pthread_rwlock_unlock(&rwlock);
#endif
// other threads do below
pthread_rwlock_wrlock(&rwlock);
queue.pop_back();
pthread_rwlock_unlock(&rwlock);
それは私の理解していません。
情報や提案は私にとって大きな助けになります!
下手な英語でごめんなさい!