Re: regarding isolation between threads - Mailing list pgsql-general

From Richard Huxton
Subject Re: regarding isolation between threads
Date
Msg-id 42FB3941.9080006@archonet.com
Whole thread Raw
In response to regarding isolation between threads  ("Surabhi Ahuja " <surabhi.ahuja@iiitb.ac.in>)
List pgsql-general
Surabhi Ahuja wrote:
> void *connect(void* threadid)
> {
>     char command[100];
>     int *id_ptr, taskid;
>     id_ptr = (int *) threadid;
>     taskid = *id_ptr;
>     if(taskid == 0)
>         strcpy(command, "select insert (1)");
>     else if(taskid == 1)
>         strcpy(command, "select insert (1)");
...

> the kind of output i am expecting is:
>
> table x: 1 3 4 5
> table a: 1
> and no error message
>
> but the output is something like
>
> table x : 1 3 4 5
> table some_other_table :
> it has nothing
> and error message is displayed : "error in stored proc "insert(..... primary key violation .."
> this error is because
>
> two threads are simultaneoulsy trying to insert the values "1" each and thats where they interfere with each other.

That's because that's what you've asked them to do (see code fragment).

Oh, and personally, I think "insert" is a bad name for a function - it
just took me 5 minutes to figure out what you meant.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: "Surabhi Ahuja "
Date:
Subject: regarding isolation between threads
Next
From: Jeff Boes
Date:
Subject: Re: World-wide Stop Order on PERL,Python,Java::->> Use