Robert S. Barnes
Robert S. Barnes

Reputation: 40558

Is Perl's inet_aton thread-safe?

Is inet_aton Thread-Safe? I know according to UNP that POSIX doesn't require a lot of the Sockets API to be thread safe, and so I have to assume they're not, but in general how do I know if something is thread safe in Perl? To what extent do I need to lock library function that I call? And how do I lock them? When I try something like lock(&inet_aton) it gives me an error: Can't modify non-lvalue subroutine call in lock.

And yes, I've read: Thread-Safety of System Libraries

Upvotes: 5

Views: 604

Answers (2)

Leon Timmermans
Leon Timmermans

Reputation: 30225

The function inet_aton doesn't have any state it keeps between function calls, so I don't see any reason why it wouldn't be thread safe (provided the arguments you pass it aren't shared between threads).

Upvotes: 2

David Schmitt
David Schmitt

Reputation: 59346

If you read the inet_aton manpage carefully you will see that this call does not use any shared state (contrary to the inet_ntoa function described in the same manpage), and thus should be thread safe.

That the function writes its result into a caller-provided structure also supports this.

Perl uses a thin wrapper on top of those functions and thus doesn't change the thread safety of the underlying library.

Upvotes: 2

Related Questions