Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Mojo/IOLoop/ReadWriteProcess/Shared/Memory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ sub lock_section {

sub stat { shift->_shared_memory->stat }

sub DESTROY { $_[0]->remove if $_[0]->destroy() }
sub DESTROY {
my $self = shift;
if ($self->_shared_memory) {
eval { $self->_shared_memory->detach() };
}
$self->remove if $self->destroy();
}

!!42;
15 changes: 10 additions & 5 deletions lib/Mojo/IOLoop/ReadWriteProcess/Shared/Semaphore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ sub _genkey { ftok($0, 0) }
sub _create {
my ($self, $key) = @_;

# Try acquiring already existing semaphore
my $sem = IPC::Semaphore->new($key, $self->count, 0);
unless (defined $sem) {
# Try creating it. IPC_EXCL in flags fails with EEXIST if it already

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence isn't really comprehensible. What is "it" referring to? Maybe:

Suggested change
# Try creating it. IPC_EXCL in flags fails with EEXIST if it already
# Try acquiring a possibly existing semaphore using the IPC_EXCL flag. This will fail with EEXIST if it already

# exists, e.g. from a previous call, or a concurrent process that won the
# race to create it - both cases are handled the same way: attach to it.
my $sem = IPC::Semaphore->new($key, $self->count, $self->flags);
if (defined $sem) {
warn "[debug:$$] Create semaphore $key" if DEBUG;
$sem = IPC::Semaphore->new($key, $self->count, $self->flags);
confess 'Semaphore creation failed! ' unless defined($sem);
$sem->setall($self->_value);
}
else {
warn "[debug:$$] Attach to existing semaphore $key" if DEBUG;
$sem = IPC::Semaphore->new($key, $self->count, 0);
}
confess 'Semaphore creation failed! ' unless defined($sem);
return $sem;
}

Expand Down
2 changes: 1 addition & 1 deletion t/02_parallel.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ subtest batch => sub {
separate_err => 0,
set_pipes => 1
);
$c->start();
$c->last->start();
is $c->last->getline, "Hello world 3\n";
$c->wait_stop();

Expand Down
Loading