[Boost-Users][interprocess]ERROR_ACCESS_DENIED when removing a message_queue

Hi, I'm a beginner with boost, so please don't throw things at me ... I'm using boost message_queue in a sample program, on Windows, that just does : - create the message_queue - remove the message_queue It works fine, if my program does this : try { message_queue mq1(create_only, "toto", 10, 100); } catch (interprocess_exception &err) { return -1; } message_queue::remove("toto"); but if it does : message_queue *mq1=0; try { mq1 = new message_queue(create_only, "toto", 10, 100); } catch (interprocess_exception &err) { return -1; } message_queue::remove("toto"); then the remove return ERROR_ACCESS_DENIED (on tthe DeleteFile call). I don't understand why. Is somebody can tell me what is wrong with my code ? Thanks for your reply.

Laurence Chambenois wrote:
It works fine, if my program does this : try { message_queue mq1(create_only, "toto", 10, 100); } catch (interprocess_exception &err) { return -1; }
message_queue::remove("toto");
but if it does : message_queue *mq1=0;
try { mq1 = new message_queue(create_only, "toto", 10, 100); } catch (interprocess_exception &err) { return -1; }
message_queue::remove("toto");
then the remove return ERROR_ACCESS_DENIED (on tthe DeleteFile call). I don't understand why. Is somebody can tell me what is wrong with my code ?
Just a wild guess: That's probably because the message queue is still open by the object mq1 points to. In the case where it works, mq1 is destroyed before the call to remove("toto").

AMDG Laurence Chambenois wrote:
but if it does :
message_queue *mq1=0;
try { mq1 = new message_queue(create_only, "toto", 10, 100); } catch (interprocess_exception &err) { return -1; }
message_queue::remove("toto");
then the remove return ERROR_ACCESS_DENIED (on tthe DeleteFile call). I don't understand why. Is somebody can tell me what is wrong with my code ?
I suspect that the problem is that in the second case you are trying to remove a message queue which you still have a handle to. In the first case, mq1 goes out of scope. In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
I suspect that the problem is that in the second case you are trying to remove a message queue which you still have a handle to. In the first case, mq1 goes out of scope.
In Christ, Steven Watanabe
Thanks Steven, Just a note: In Boost to 1.39 windows will get the same behaviour as unix (you can remove in-use shared memory or named objects), so I hope portability will be increased. This in-use removal has been implemented using native NT system calls, so that the in-use file is renamed and marked as deleted when the last handle is closed. Attached processes will continue working in the resource until the last handle is closed, just like in UNIX. Best, Ion
participants (4)
-
Eric MALENFANT
-
Ion Gaztañaga
-
Laurence Chambenois
-
Steven Watanabe