[ 
https://issues.apache.org/jira/browse/PIG-1973?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13022584#comment-13022584
 ] 

Woody Anderson commented on PIG-1973:
-------------------------------------

incorrect.

initialValue is invoked when get() is first called. However, in the old code, 
initialValue returns null b/c it was not overridden.
thus, if 2 threads call getUDFContext() at the same time they may get 2 
different UDFContext objects, b/c the method 
does an unprotected comparison/set check:

{code}
     public static UDFContext getUDFContext() {
        if (tss.get() == null) {
            UDFContext ctx = new UDFContext();
            tss.set(ctx);
        }
        return tss.get();
     }
{code}

this is CLASSIC race condition.


> UDFContext.getUDFContext has a thread race condition around it's ThreadLocal
> ----------------------------------------------------------------------------
>
>                 Key: PIG-1973
>                 URL: https://issues.apache.org/jira/browse/PIG-1973
>             Project: Pig
>          Issue Type: Bug
>          Components: impl
>    Affects Versions: 0.8.0, 0.9.0
>            Reporter: Woody Anderson
>            Assignee: Woody Anderson
>            Priority: Minor
>             Fix For: 0.9.0
>
>         Attachments: 1973.patch
>
>
> this is probably isn't manifesting anywhere, but it's an incorrect use of the 
> ThreadLocal pattern.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to