I played with boost :: interprocess and accidentally asked the same question. I dug a little before finally settling on open_or_create for my needs. However, deep in the bowels of the spaghetti template, which is boost (my 1.62), we find this gem:
/*<... snip ...>*/ //This loop is very ugly, but brute force is sometimes better //than diplomacy. If someone knows how to open or create a //file and know if we have really created it or just open it //drop me a e-mail! bool completed = false; spin_wait swait; while(!completed){ try{ create_device<FileBased>(dev, id, size, perm, file_like_t()); created = true; completed = true; } catch(interprocess_exception &ex){ if(ex.get_error_code() != already_exists_error){ throw; } else{ try{ DeviceAbstraction tmp(open_only, id, read_write); dev.swap(tmp); created = false; completed = true; } catch(interprocess_exception &e){ if(e.get_error_code() != not_found_error){ throw; } } catch(...){ throw; } } } catch(...){ throw; } swait.yield(); } /* <... snip ...> */
The above information is located in the manage_open_or_create_impl.hpp file approximately on line 360 ββin the priv_open_or_create () method. The answer seems to be no. No, there is no good way to check if a shared memory has been created before trying to open it.
source share