Skip to content

Conversation

@ITHelpDec
Copy link

PR in response to issue #39.


In order for this code to run, we must perform the following commits and amend listing 6.1 to return an empty shared pointer at line 37 instead of throwing.

// if(data.empty()) throw empty_stack();
if(data.empty()) return std::shared_ptr<T>();

Tested with a simple list of ints, but will investigate with larger containers of varying types to benchmark speed comparisons.

Test case - (click to expand / collapse)
template <typename T>
void print_list(const std::list<T> &il) {
    for (auto &&e : il) {
        std::cout << e << ' ';
    } std::cout << '\n';
}

int main()
{
    std::list<int> il = { 1, 4, 5, 3, 6, 7, 4 };
    print_list(il);
    
    auto sorted_il = parallel_quick_sort(il);
    print_list(sorted_il);
    
    return 0;
}

// 1 4 5 3 6 7 4 
// 1 3 4 4 5 6 7 
// Program ended with exit code: 0

I'm attempting to try implement the same sorter with our lock-free stack, but issues exist in all of the implementations provided in chapter 7, and boost is showing data races with Thread Sanitiser, so I'll come back to this when I know where to start.


A relatively simple fix, but it would just be nice if it worked out of the box instead of having to correct it.

- there is only one instance of "thread_safe_stack" in the entire book (this example)
- in every other instance, the container is named "threadsafe_stack" (only one underscore)
- listing 6.1 does not use boost::shared_ptr<> (there don't seem to be any other instances of boost::shared_ptr<> in the book)
- we can either change this or modify 6.1 (although we need to modify it anyway to prevent the throw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant