Stanislav Kirichenko’s Post

The 𝗰𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 is useful 𝗳𝗼𝗿 𝗺𝘂𝗹𝘁𝗶𝘁𝗵𝗿𝗲𝗮𝗱 𝗰𝗼𝗺𝗺𝘂𝗻𝗶𝗰𝗮𝘁𝗶𝗼𝗻. The pattern has many variants, including templates, unions, polymorphism or std::variant, type erasure etc... Every problem requires a different specific solution, thus a different implementation. This version of the 𝗖𝗼𝗺𝗺𝗮𝗻𝗱 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 uses a function pointer, simplest form to implement in C. This pattern is perfect to pair with a 𝗹𝗼𝗰𝗸-𝗳𝗿𝗲𝗲 𝗿𝗶𝗻𝗴 𝗯𝘂𝗳𝗳𝗲𝗿 or 𝗾𝘂𝗲𝘂𝗲, one way communication between threads, The command pattern AFAIK is also heavily used in Job/Task systems. If you think about it, if we could move the ownership of everything from a thread to another one, would this make multithreading easier to write? Save this post and give it a try! #programming #code #C++

To view or add a comment, sign in

Explore content categories