- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I took an example from the TBB tutorial pdf.
And created my own program.
It shows the following compilation error:
[bash]std::vectorMyVector;
typedef spin_rw_mutex MyVectorMutexType;
MyVectorMutexType MyVectorMutex;
void AddKeyIfMissing( const string& key ) {
// Obtain a reader lock on MyVectorMutex
MyVectorMutexType::scoped_lock
lock(MyVectorMutex,/*is_writer=*/false);
size_t n = MyVector.size();
for( size_t i=0; iif( MyVector==key ) return;
if( !MyVectorMutex.upgrade_to_writer() )
// Check if key was added while lock was temporarily released
for( int i=n; iif(MyVector==key ) return;
vector.push_back(key);
}
[/bash]
And created my own program.
[bash]#include
#include
#include
using namespace std;
using namespace tbb;
typedef spin_rw_mutex myMutex;
myMutex sm;
int i=0;
void writerFunction()
{
{
myMutex::scoped_lock lock(sm,/*is writer=*/true);
++i;
sm.downgrade_to_reader();
//sm.upgrade_to_writer();
cout<<"wrote value "<<}
}
int main()
{
tbb_thread my_thread1(writerFunction);
tbb_thread my_thread2(writerFunction);
my_thread1.join();
my_thread2.join();
cout<<"Value of i = " << i <}[/bash]
It shows the following compilation error:
[bash]spin_rw_mutex.cpp: In function void writerFunction():I had a look at the spin_rw_mutex_v3.hpp file. It shows that downgrade_to_reader is within scoped_lock. If that's so, I'm confused as to how the function is accessed as a mutex instance member in the tutorial example. What am I doing/understanding wrong?
spin_rw_mutex.cpp:25: error: class myMutex has no member named downgrade_to_reader
bash: ./spin_rw_mutex: No such file or directory
[/bash]
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's an error in the Tutorial; thank you for pointing it out!
Upgrading/downgrading should be done through the scoped_lock object, not through the mutex object. We will fix the Tutorial.
Upgrading/downgrading should be done through the scoped_lock object, not through the mutex object. We will fix the Tutorial.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's an error in the Tutorial; thank you for pointing it out!
Upgrading/downgrading should be done through the scoped_lock object, not through the mutex object. We will fix the Tutorial.
Upgrading/downgrading should be done through the scoped_lock object, not through the mutex object. We will fix the Tutorial.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah! So I just had to use
lock.downgrade_to_reader();
T'was as simple as that! Thanks! :)
lock.downgrade_to_reader();
T'was as simple as that! Thanks! :)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page