Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

If I remember correctly, C++11 smart pointers need more maintenance when being passed on a message pump across threads, particularly from my memory of using it on Windows.[0]

When sending/posting a smart pointer to a different thread's message pump via a function like PostThreadMessage, the sending thread's smart pointer would go out of scope and the memory would be released because the receiving thread hadn't increased the reference count. By the time the receiving thread's message pump processed it, the pointer had already gone out of scope.

If you are using the producer-consumer pattern, most likely you'll have to use unique pointers and call release manually; I guess that's still better than using new and delete, right? Or perhaps I could try using SendMessage instead of PostMessage and read the return value to determine if the pointer got to the other side (for some reason, that wasn't an option to me).

[0] http://stackoverflow.com/questions/11290912/passing-objects-...



I assume that postthreadmessage has a C abstraction. In C++ you should use a queue that properly supports copyable and movable types. Or at the very least write a wrapper on top of postthreadmessage that does.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: