Persistent Datastructures
Many moons ago I wrote a short tutorial on pthreads. It was adopted (with permission) by a number of universities to provide a brief introduction for their students doing pthread based coursework. It strikes me as bizzare, but the tutorial remains the top google hit for 'pthreads tutorial'. Consequently I periodically get requests for help with threading issues.
When I wrote the tutorial I was still enamoured with threads, an infatuation that didn't last very long :). Since then, my experience working with pthreads, auto-parallelising compilers, java, erlang, kowari, and 10 years of professional programming, have fundamentally changed my perspective on how to approach concurrency.
- Concurrency bad
- See 1
- Shared-memory concurrency very very bad
- see 3
- Process isolation good
- Message-Passing/Rendevous good
- Co-routine/Continuation good
- Locks are bad - you've accepted all the pain and suffering associated with shared-memory concurrency, and now you're going to SERIALISE operations!!
Assuming you are stuck using shared-memory threads, what do you do now? Well first hope like hell you have a garbage collector. If you don't it is going to hurt enough I would suggest you give up now and go back and reconsider the reasons why you discounted the other options above -- anything is better than this. If you do have a garbage collector, start reading up on persistent datastructures.
Persistent datastructures are very important in safe efficient thread-based design because they don't require locking. They are called persistant because they are immutable. Once you have a reference to a structure that structure is guaranteed const. What this means is that any method that would mutate an empherial (ie, what you are used to) structure returns a new structure.
As an example consider a list
x = [] | x = null
y = x.prepend(1) | y = { 1, x }
z = y.prepend(2) { z = { 2, y }
Now if you need the rest of your program to see the updated list you use some sort of reference cell. The simplest is just a one element queue. This is a classic reader-writer problem; except you don't have to worry about evicting readers before the writer does his thing.
RefCellNote there is almost no contention for readers, no book-keeping, and once a reader has a reference to data, all further access to the structure is lock-free.: init(T data); // Initialises the cell with data. All subsequent access to data must originate with this cell. T read(); // Returns the current value of data (internally access is protected by the 'access lock'). T writeLock(); // Obtains the 'write lock' (or blocks), and returns the current value of data. unLock(T data); // Updates the current value of data under the 'access lock', and releases the 'write lock'.
However take another look at it. Step back and think about what this is and you will realise that what we have written here is a transaction based datastore. What this means is that you can now go examine all your transaction management theory and introduce multiple-writers, lock-stealing, etc, et al. Now as long as T is persistent, you are atomic, consistent, and isolated. If you ensure unLock flushes the structure to disk you now have an ACID datastore (surprised? :). Add consistency checks to the mutation operations and you can call it a database :).
Granted, without a garbage collector, memory management is a bitch. The standard reference on persistent structures is Chris Okasaki. A quick google will get you a fair way; however citeseer is the motherlode. If you have access to a university library, I would lookup his book (Purely Functional Data Structures), which will save you alot of searching on citeseer :).
Another thing worth noting is that it is worth noting is that once you leave the ephemeral space, you need to start making decisions beyond the simple "Vector/List/Hash/Tree". There are alot more tradeoffs to consider. Do you really need the efficient random-access of a vector, or are you actually using it as a queue, or dqueue? A persistent queue can be implemented with O(1) amortized operations, but the best I have been able to find (quickly) for a true 'vector' is log(i) access (i = index) [citeseer]. Just as importantly, a persistant queue is very simple, almost identical in fact to an efficient ephemeral queue; whereas a persistant random-access-list much more complicated than a vector.



22 Comments:
My sources tell me that you probably want to read the paper referred to near the bottom of this report from PLDI 2005.
I found a PDF copy of the paper; it is
Threads Cannot be Implemented as a Library by Boehm.
By
Anonymous, at 3:18 PM, August 18, 2005
Hello,
I am searching for fresh information
for my cc Infopage, 30,000 daily updated Information Pages about all kind of subjects.
It might interest you to know that your blog has been visited and has been read. I hope you enjoy your "Blogging".
I wish you all the luck I can, keep the good work going!
Kind regards,
Jos
Today's News From & About Google
By
cc Infopage, at 1:26 PM, October 12, 2005
I found a lot of useful info about Book Keeping on your blog - thank you. I also have a new Book Keeping Tips blog - please click over and have a look
By
jasmine, at 7:21 PM, October 13, 2005
Blogs are a blast....So is my facial info niche remember site. Check it out for yourself facial info niche remember
By
Paul, at 6:01 AM, October 25, 2005
golf clipart
By
eagle clipart, at 4:15 PM, October 27, 2005
That sounds great, but free color contact lens sample has links to different reviews.
By
Anonymous, at 6:47 AM, November 02, 2005
Hi Shammah, I was looking around for information about invoicing and found your Persistent Datastructures post. It's not bang on what I was looking for but it was a good read so I'm glad I found it! I can see why it showed up when I searched on the term 'invoicing'. Thanks a lot and I'll stop by again :-)
By
vat, at 11:38 AM, November 05, 2005
I was just browsing various blogs as I was doing a search on the word poster, and I just wanted to say that I really like what you've done with your blog, even though it wasn't particularly related to what I searched for. I appreciate your postings, and your blog is a good example of how a blog should be done. I've only just recently started a Posters website - feel free to visit it when you get a chance if you wish. Much success, antonio.
By
Antonio Hicks, at 8:32 AM, November 10, 2005
You'll receive Valuable how-to Lessons, Millions and Millions of FREE Ads, and High in Demand Software Applications
By
Anonymous, at 9:39 PM, November 11, 2005
Greatest Blog Post. Please visit this site on advantage of long distance relationship
advantage of long distance relationship
By
Anonymous, at 5:42 PM, November 14, 2005
A dying man needs to die, as a sleepy man needs to sleep, and there comes a time when it is wrong, as well as useless, to resist.
Stewart Alsop- Posters.
By
Blog World, at 8:19 PM, November 21, 2005
relationship dating 101 Ways to Build Happy, Lasting Relationships.
Multilingual : English - Chinese Simplified - Chinese Traditional - Dutch - French - German - Greek - Italian - Japanese - Korean - Portuguese - Russian - Spanish
Make Eye Contact : Think back to the first time you saw your now mate. relationship dating
By
Pamela, at 11:19 AM, December 30, 2005
Thank you for the informative blog
Here Is some additional
Contact Lens Resources for daily wear,dipsposable, and color contact lense if you or your readers are interested.
By
Shawn T Lippert, at 6:55 PM, January 26, 2006
love relationship 101 Ways to Build Happy, Lasting Relationships.
Multilingual : English - Chinese Simplified - Chinese Traditional - Dutch - French - German - Greek - Italian - Japanese - Korean - Portuguese - Russian - Spanish
Start Over : When couples first get together, everything is new and exciting.
Lighten Up : Often when couples have gone through or are going through some bumpy spots in their relationship, things tend to get serious.
Night of Passion : Intimacy and passion in relationships is not only important but also healthy.
Cuddle Time : When couples first start dating, cuddling is usually a part of their everyday existence.
Make the Women Feel Good : Just like men, woman love feeling good about themselves.
Showing Love : Although hearing the words, I love you is special and important.
Realistic Expectations : No matter how wonderful and flawless your mate seems, no one is perfect.
Go on a Date : Especially for married couples, but even for some dating couples, start dating.
Control Your Anger : Every relationship has difficulties, and sometimes, there can be some intense arguments.
I Forgive You : If something has happened in your relationship causing the trust to waiver, you will have many things to work through.
Day at the Movies : Have a movie marathon some rainy or cold Saturday.
Dinner by the Fire : Order in some of your favorite food, open a bottle of fine wine, light some candles.
A Day at the Spa : Show your appreciation for the hard work that takes.
Keep in Touch : It is important that you keep in touch with each other often.
Motivate Each Other : Find a mutual incentive that will motivate both of you.
Adore your Mate : Appreciate and love them for the person they are.
Make Eye Contact : Think back to the first time you saw your now mate.
Respect Privacy : When two people come together in a relationship, each person has their own set of history.
Be Flexible : There will be times when your mate is right and times when you are right.
Encourage Friendships : Men, unlike women, have a more difficult time in developing close friendships with other men.
love relationship
By
Michelle, at 7:38 PM, February 06, 2006
There are a few desires (if any) stronger than the deep wish to be liked, the first time you realized that not everybody liked you, it was a shock.
Link to this site: relationship romantic
http://relationship-faq.info/
By
joel, at 12:19 PM, February 10, 2006
Just blogging for a while, my site is also about free music download sites, so just saying what's up.
Charles
By
download music free, at 3:31 AM, March 09, 2006
relationship quote 101 Ways to Build Happy, Lasting Relationships.
Multilingual : English - Chinese Simplified - Chinese Traditional - Dutch - French - German - Greek - Italian - Japanese - Korean - Portuguese - Russian - Spanish
Start Over : When couples first get together, everything is new and exciting.
Lighten Up : Often when couples have gone through or are going through some bumpy spots in their relationship, things tend to get serious.
Night of Passion : Intimacy and passion in relationships is not only important but also healthy.
Cuddle Time : When couples first start dating, cuddling is usually a part of their everyday existence.
Make the Women Feel Good : Just like men, woman love feeling good about themselves.
Showing Love : Although hearing the words, I love you is special and important.
Realistic Expectations : No matter how wonderful and flawless your mate seems, no one is perfect.
Go on a Date : Especially for married couples, but even for some dating couples, start dating.
Control Your Anger : Every relationship has difficulties, and sometimes, there can be some intense arguments.
I Forgive You : If something has happened in your relationship causing the trust to waiver, you will have many things to work through.
Day at the Movies : Have a movie marathon some rainy or cold Saturday.
Dinner by the Fire : Order in some of your favorite food, open a bottle of fine wine, light some candles.
A Day at the Spa : Show your appreciation for the hard work that takes.
Keep in Touch : It is important that you keep in touch with each other often.
Motivate Each Other : Find a mutual incentive that will motivate both of you.
Adore your Mate : Appreciate and love them for the person they are.
Make Eye Contact : Think back to the first time you saw your now mate.
Respect Privacy : When two people come together in a relationship, each person has their own set of history.
Be Flexible : There will be times when your mate is right and times when you are right.
Encourage Friendships : Men, unlike women, have a more difficult time in developing close friendships with other men.
relationship quote
By
relationship advice guide, at 1:27 PM, April 08, 2006
relationship tip 101 Ways to Build Happy, Lasting Relationships.
Multilingual : English - Chinese Simplified - Chinese Traditional - Dutch - French - German - Greek - Italian - Japanese - Korean - Portuguese - Russian - Spanish
Start Over : When couples first get together, everything is new and exciting.
Lighten Up : Often when couples have gone through or are going through some bumpy spots in their relationship, things tend to get serious.
Night of Passion : Intimacy and passion in relationships is not only important but also healthy.
Cuddle Time : When couples first start dating, cuddling is usually a part of their everyday existence.
Make the Women Feel Good : Just like men, woman love feeling good about themselves.
Showing Love : Although hearing the words, I love you is special and important.
Realistic Expectations : No matter how wonderful and flawless your mate seems, no one is perfect.
Go on a Date : Especially for married couples, but even for some dating couples, start dating.
Control Your Anger : Every relationship has difficulties, and sometimes, there can be some intense arguments.
I Forgive You : If something has happened in your relationship causing the trust to waiver, you will have many things to work through.
Day at the Movies : Have a movie marathon some rainy or cold Saturday.
Dinner by the Fire : Order in some of your favorite food, open a bottle of fine wine, light some candles.
A Day at the Spa : Show your appreciation for the hard work that takes.
Keep in Touch : It is important that you keep in touch with each other often.
Motivate Each Other : Find a mutual incentive that will motivate both of you.
Adore your Mate : Appreciate and love them for the person they are.
Make Eye Contact : Think back to the first time you saw your now mate.
Respect Privacy : When two people come together in a relationship, each person has their own set of history.
Be Flexible : There will be times when your mate is right and times when you are right.
Encourage Friendships : Men, unlike women, have a more difficult time in developing close friendships with other men.
relationship tip
By
relationship advice guide, at 7:20 PM, April 08, 2006
online relationship 101 Ways to Build Happy, Lasting Relationships.
Multilingual : English - Chinese Simplified - Chinese Traditional - Dutch - French - German - Greek - Italian - Japanese - Korean - Portuguese - Russian - Spanish
Start Over : When couples first get together, everything is new and exciting.
Lighten Up : Often when couples have gone through or are going through some bumpy spots in their relationship, things tend to get serious.
Night of Passion : Intimacy and passion in relationships is not only important but also healthy.
Cuddle Time : When couples first start dating, cuddling is usually a part of their everyday existence.
Make the Women Feel Good : Just like men, woman love feeling good about themselves.
Showing Love : Although hearing the words, I love you is special and important.
Realistic Expectations : No matter how wonderful and flawless your mate seems, no one is perfect.
Go on a Date : Especially for married couples, but even for some dating couples, start dating.
Control Your Anger : Every relationship has difficulties, and sometimes, there can be some intense arguments.
I Forgive You : If something has happened in your relationship causing the trust to waiver, you will have many things to work through.
Day at the Movies : Have a movie marathon some rainy or cold Saturday.
Dinner by the Fire : Order in some of your favorite food, open a bottle of fine wine, light some candles.
A Day at the Spa : Show your appreciation for the hard work that takes.
Keep in Touch : It is important that you keep in touch with each other often.
Motivate Each Other : Find a mutual incentive that will motivate both of you.
Adore your Mate : Appreciate and love them for the person they are.
Make Eye Contact : Think back to the first time you saw your now mate.
Respect Privacy : When two people come together in a relationship, each person has their own set of history.
Be Flexible : There will be times when your mate is right and times when you are right.
Encourage Friendships : Men, unlike women, have a more difficult time in developing close friendships with other men.
online relationship
By
relationship advice guide, at 12:51 PM, April 09, 2006
relationship quote 101 Ways to Build Happy, Lasting Relationships.
Multilingual : English - Chinese Simplified - Chinese Traditional - Dutch - French - German - Greek - Italian - Japanese - Korean - Portuguese - Russian - Spanish
Start Over : When couples first get together, everything is new and exciting.
Lighten Up : Often when couples have gone through or are going through some bumpy spots in their relationship, things tend to get serious.
Night of Passion : Intimacy and passion in relationships is not only important but also healthy.
Cuddle Time : When couples first start dating, cuddling is usually a part of their everyday existence.
Make the Women Feel Good : Just like men, woman love feeling good about themselves.
Showing Love : Although hearing the words, I love you is special and important.
Realistic Expectations : No matter how wonderful and flawless your mate seems, no one is perfect.
Go on a Date : Especially for married couples, but even for some dating couples, start dating.
Control Your Anger : Every relationship has difficulties, and sometimes, there can be some intense arguments.
I Forgive You : If something has happened in your relationship causing the trust to waiver, you will have many things to work through.
Day at the Movies : Have a movie marathon some rainy or cold Saturday.
Dinner by the Fire : Order in some of your favorite food, open a bottle of fine wine, light some candles.
A Day at the Spa : Show your appreciation for the hard work that takes.
Keep in Touch : It is important that you keep in touch with each other often.
Motivate Each Other : Find a mutual incentive that will motivate both of you.
Adore your Mate : Appreciate and love them for the person they are.
Make Eye Contact : Think back to the first time you saw your now mate.
Respect Privacy : When two people come together in a relationship, each person has their own set of history.
Be Flexible : There will be times when your mate is right and times when you are right.
Encourage Friendships : Men, unlike women, have a more difficult time in developing close friendships with other men.
relationship quote
By
relationship advice guide, at 2:55 PM, April 09, 2006
long distance relationship 101 Ways to Build Happy, Lasting Relationships.
Start Over : When couples first get together, everything is new and exciting.
Lighten Up : Often when couples have gone through or are going through some bumpy spots in their relationship, things tend to get serious.
Night of Passion : Intimacy and passion in relationships is not only important but also healthy.
Cuddle Time : When couples first start dating, cuddling is usually a part of their everyday existence.
Make the Women Feel Good : Just like men, woman love feeling good about themselves.
Showing Love : Although hearing the words, I love you is special and important.
Realistic Expectations : No matter how wonderful and flawless your mate seems, no one is perfect.
Go on a Date : Especially for married couples, but even for some dating couples, start dating.
Control Your Anger : Every relationship has difficulties, and sometimes, there can be some intense arguments.
I Forgive You : If something has happened in your relationship causing the trust to waiver, you will have many things to work through.
Day at the Movies : Have a movie marathon some rainy or cold Saturday.
Dinner by the Fire : Order in some of your favorite food, open a bottle of fine wine, light some candles.
A Day at the Spa : Show your appreciation for the hard work that takes.
Keep in Touch : It is important that you keep in touch with each other often.
Motivate Each Other : Find a mutual incentive that will motivate both of you.
Adore your Mate : Appreciate and love them for the person they are.
Make Eye Contact : Think back to the first time you saw your now mate.
Respect Privacy : When two people come together in a relationship, each person has their own set of history.
Be Flexible : There will be times when your mate is right and times when you are right.
Encourage Friendships : Men, unlike women, have a more difficult time in developing close friendships with other men.
long distance relationship
By
relationship advice guide, at 12:59 AM, April 17, 2006
Hi, I think you have a great blog here, if you get a chance, check mine out. It's about PSP movie download software PSP movie download software. Let me know what you think
By
CQNVXGJG, at 6:03 AM, June 19, 2006
Post a Comment
<< Home