[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Concurrent B+Tree

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 15
Thread images: 1

File: 1428546514588.jpg (202KB, 1980x1076px) Image search: [Google]
1428546514588.jpg
202KB, 1980x1076px
Hey /wsr/ I need some help I have to modify this :

https://github.com/uit-inf-2202-f16/assignment-1/blob/master/precode/bpt.c

To have a concurrent B+Tree with Pthread but I don't know where I should star...

Some help would be appreciate!
>>
>>181217
- read https://computing.llnl.gov/tutorials/pthreads/#Mutexes
- port b-tree code to pthreads
- use mutexes to protect data structures that can't withstand concurrent modification or read-during-modification

Granularity of mutexing should be proportional to how much the assignment is worth. If it's just "introduction to threads", global write lock should suffice.
>>
>>181219
Thank you! I'll read that, but, if you go line 1416, 1430 and there is other, mutexing is already use....
>>
>>181217
>https://github.com/uit-inf-2202-f16/assignment-1/blob/master/precode/bpt.c
Actually, he's already done "port b-tree code to pthreads" for you, so all you need to do is identify the structures that need protected, and mutex them.
>>
>>181220
That's just boilerplate to create a barrier out of a mutex, which is later used by the test harness so the main thread of the harness can wait on all the worker threads finishing.

It's worth reading it to see how it's done, and see if there's anything in there you can reuse.
>>
>>181221
So i have to modify the method "do_test" or directly insert/delete/update methods?
>>
So if I got it, line : 1838

for (i = 0; i<num_thread; i++)
pthread_join (pid[i], NULL);

If I change that for :

for (i = 0; i<num_thread; i++){
pthread_mutex_lock (myMutex);
pthread_join (pid[i], NULL);
pthread_mutex_unlock (myMutex);
}

It will works?
>>
Or, no, more at line 1800 when we call the "insert" function
>>
>>181224
>So i have to modify the method "do_test" or directly insert/delete/update methods?
Don't modify do_test.

Modify the tree methods so that do_test passes.

What you need is a readers-writer lock, which appears simple, but is fundamental to OS programming; Ph.Ds have been written on readers-writer locking.

To read the structure, you need to get a read lock (which there can be many of); to modify the structure you need to get a write lock, which you can only get if no-one has a read lock. Writers can starve if the structure is being read all the time, so most implementations delay handing out more read locks if there's a writer waiting on a write lock.

Given that this seems to be an "intro-to-pthreads" course, I'm gonna guess you're allowed to use pthread_rwlock, which is documented quite well here: https://docs.oracle.com/cd/E19455-01/806-5257/6je9h032m/index.html .

If you were writing it yourself, you'd probably use something like a counting lock for the readers, and a two-stage lock for the writers, so a writer can take stage one of the write lock and this stops further readers from getting more read locks.
>>
Ok, i'll try that!
>>181230
>>
>>181226
You need to be using the same mutex for each lock, so make sure you've defined myMutex in the global scope, like in line 1494.
>>
>>181232
Hum... do_test only call insert method, which call a finding method, so I only have to modify those with read lock !?
>>
>>181287
If you've already acquired the write lock, you don't need the read lock.

You need to check for this, because when the write lock is held, you can't acquire read locks, so if you have the write lock and try to take a read lock, you'll never be given it, and your writer will wait forever.

Because it's doing this while holding the write lock, no-one can get a write lock or a read lock, and your entire datastructure ends up deadlocked.
>>
>>181230
Can you explain my what is "counting lock" and "two-stage lock"

Can I use this example to my case ?

https://groups.google.com/forum/#!topic/comp.unix.programmer/4ZkoPLmZxGQ
>>
>>181609
I use spin lock! But thank you for your advices
Thread posts: 15
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.