Multithread select/update

  • Thread starter Thread starter Pablo Ricco
  • Start date Start date
P

Pablo Ricco

Hello
I am developing a multi-thread app.
In this, each thread must take a number from a table and then update
table with the number + 1. This number is to insert in other table by
primary key. My problem is while I select number and update number,
because other thread may be read this number too.
How I can resolve this problem?...
I can't use Autonumber.

thank you
Pablo
 
Hi Pablo,

Out of curiosity, why can't you use AutoNumber?
Anyway, you might create a table in database that holds current number, and
do a read/increase in a transaction - this will gurantee you that no thread
will get the same number.
 
I can't use Autonumber because the tables are generated with GeneXus Tool.
My app and GeneXus may store in the table at same time.
If I work with transaction...my thread stays locked waiting for get table
lock?
Do you have a good example to do this?

Thank You
Pablo


Miha Markic said:
Hi Pablo,

Out of curiosity, why can't you use AutoNumber?
Anyway, you might create a table in database that holds current number, and
do a read/increase in a transaction - this will gurantee you that no thread
will get the same number.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Pablo Ricco said:
Hello
I am developing a multi-thread app.
In this, each thread must take a number from a table and then update table
with the number + 1. This number is to insert in other table by primary
key. My problem is while I select number and update number, because other
thread may be read this number too.
How I can resolve this problem?...
I can't use Autonumber.

thank you
Pablo
 
Hi,

No, I don't have an example, however, I deem pretty simple to do a select of
a number from a table and increase its value in the same transaction .

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

el Pala said:
I can't use Autonumber because the tables are generated with GeneXus Tool.
My app and GeneXus may store in the table at same time.
If I work with transaction...my thread stays locked waiting for get table
lock?
Do you have a good example to do this?

Thank You
Pablo


Miha Markic said:
Hi Pablo,

Out of curiosity, why can't you use AutoNumber?
Anyway, you might create a table in database that holds current number, and
do a read/increase in a transaction - this will gurantee you that no thread
will get the same number.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Pablo Ricco said:
Hello
I am developing a multi-thread app.
In this, each thread must take a number from a table and then update table
with the number + 1. This number is to insert in other table by primary
key. My problem is while I select number and update number, because other
thread may be read this number too.
How I can resolve this problem?...
I can't use Autonumber.

thank you
Pablo
 
Back
Top