[interprocess] Checking for existence Named Mutex
How do I check for the existence of a named resource in using boost interprocess without wrapping a open_only in a try catch block and waiting for the exception? Also are there calls for launching a process such as std::system that are nonblocking in Windows using the _spawnlp and friends calls?
On 18/08/2010 20:55, Brian Davis wrote:
How do I check for the existence of a named resource in using boost interprocess without wrapping a open_only in a try catch block and waiting for the exception?
That's the only way.
Also are there calls for launching a process such as std::system that are nonblocking in Windows using the _spawnlp and friends calls?
Interprocess does not offer process launching mechanisms. See Boost.Process candidate for such utilities. Best, Ion
How do I check for the existence of a named resource in using boost
interprocess without wrapping a open_only in a try catch block and waiting for the exception?
That's the only way.
Well you know that they say.... if first you don't succeed try... catch again. I sure hope that this is not standard coding practices for Boost.Interprocess. I have seen this before in the likes of Borland Builder (VCL) and Java and I consider this to be poor programming practices. I realize that boost is working to create a standard library to mirror the likes of Java... I just hope Boost does not mirror(copy) the bad practices as well. I hope this gets fixed in future releases. The logic here is to see if a named mutex is in existence (checking to see if process is running) if not launch the app that will create it (auto launch the app). Then take the mutex and do some stuff then release. This results in a try.. catch... fail.. try ... catch succeed. I have tested this and it works however sloppy it may be. Strange how objects created with in a shared memory region can be searched for, but not the shared memroy region itself or named mutexes. --snip from boost.interporcess documentatoin-- //Find the array res = segment.find<MyType> ("MyType array"); --end snip--
On 24/08/2010 23:56, Brian Davis wrote:
How do I check for the existence of a named resource in using boost interprocess without wrapping a open_only in a try catch block and waiting for the exception?
That's the only way.
Well you know that they say.... if first you don't succeed try... catch again. I sure hope that this is not standard coding practices for Boost.Interprocess. I have seen this before in the likes of Borland Builder (VCL) and Java and I consider this to be poor programming practices. I realize that boost is working to create a standard library to mirror the likes of Java... I just hope Boost does not mirror(copy) the bad practices as well. I hope this gets fixed in future releases.
I'll add this to my to-do list. What would be your proposal? Should we take in care also permission or mode (r/w) issues? Best, Ion
I'll add this to my to-do list. What would be your proposal? Should we take in care also permission or mode (r/w) issues?
Currently I just need to know if the named objects exist in shared memory.
Well after having looked through the documentation and trying to get to know
the API a little lately. I would like to see some things.
1) Provide the use of std::system to launching processes maybe boost::inter
process::system(...) to allow spawning a process in a non blocking fashion.
as the following code in Windows allows (on Linux I think & would work after
the command using std::system though I have not tried this):
Currently what I am using on windows:
<code>
std::string path = getenv( "PATH" );
path = "PATH=" + path;
std::cout << "The current path is " << path << std::endl;
char *pValue;
size_t len;
errno_t err = _dupenv_s( &pValue, &len, "path" );
path = pValue;
std::cout << "The current path is " << path << std::endl;
mexPrintf( "The current path is %s", path.c_str() );
if(
0 ==
_spawnlp(
_P_DETACH,
"cmd", "cmd", "/K", "dsa4DTool.exe",
NULL)
)
{
printf( "dsa4DTool lanuched sucessfully\n" );
}
else
{
printf( "dsa4DTool failed to launch\n" );
}
</code>
2) As discussed provide ability to search for every named shared memory
variable. Currently I was having problems with the code where I try to
search for a shared memory variable that may have, but not necessarily have,
already been created by the process running the code in the previous run of
the process. This may be working, but I have not had success with it yet.
The first call :
res = segment.find
Brian Davis wrote:
Well after having looked through the documentation and trying to get to know the API a little lately. I would like to see some things.
1) Provide the use of std::system to launching processes maybe boost::inter process::system(...) to allow spawning a process in a non blocking fashion.
I for one would much prefer child process launching and management to be a separate library, e.g. the library currently under consideration in the Vault. I often have need to run a child process, but have not yet encountered any need for shared memory communication.
participants (3)
-
Brian Davis
-
Ion Gaztañaga
-
Nat Goodspeed