Skip to content

ObjectData function not thread safe #12

@Florian-BACHO

Description

@Florian-BACHO

The following code demonstrate that the ObjectData function is not thread safe and throws std::runtime_error exception.

#include <thread>
#include <ipfs/client.h>

int main()
{
        auto hash = "QmcXneAawME7d3vmV3x95p3WVxczeTid7LpJW8DcH4sA5c";
        ipfs::Client ipfs("localhost", 5001);
        std::thread t1([&hash, &ipfs]() { std::string data; ipfs.ObjectData(hash, &data); });
        std::thread t2([&hash, &ipfs]() { std::string data; ipfs.ObjectData(hash, &data); });

        t1.join();
        t2.join();
        return (0);
}

On MacOS:
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Failed initialization

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions