This is a discussion on Thread safety within the MySQL General forum forums, part of the MySQL category; --> Dear All: I have a table T1 with these columns: location - varchar odd_even - varchar I have a ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Dear All: I have a table T1 with these columns: location - varchar odd_even - varchar I have a php page that is called from VC applications installed in 5 different locations (L1, L2, L3, L4 and L5). The page returns 0 or 1 depending on even call or odd call from each location. (1st, 3rd, 5th, 7th... page calls are odd and 2, 4, 6, 8 are even.) The page has this logic: select odd_even from T1 where location = '$location' if (odd_even == 'odd') update T1 set odd_even = 'even' where location = '$location' and odd_even = 'odd'; return '0'; else update T1 set odd_even = 'odd' where location = '$location' and odd_even = 'even'; return '1'; But since each location calls the page in very quick succession (a location have have several parallel calls running - its a multi threaded app), there is a race condition. And at times several continuous calls return same result (odd or even). How do I achieve thread safety? Please help. Its urgent. Thanks. Ravi. |
| ||||
| I'm pretty sure that the only way to do this is to use an engine (such as InnoDB) that supports transactions across multiple statements. You need some global resource that is single-threaded, and unless you have something in a file system somewhere that supports locking there I don't see any ready way to do this. Remember, however unlikely any collision that might happen eventually will. You can't fix this problem without a location-wide single-threaded resource. Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 > -----Original Message----- > From: Ravi Kumar. [mailto:ravi.kumar@cbayindia.com] > Sent: Thursday, December 07, 2006 7:18 AM > To: mysql@lists.mysql.com > Subject: Thread safety > > Dear All: > > I have a table T1 with these columns: > > location - varchar > odd_even - varchar > > I have a php page that is called from VC applications installed in 5 > different locations (L1, L2, L3, L4 and L5). The page returns 0 or 1 > depending on even call or odd call from each location. (1st, 3rd, 5th, > 7th... page calls are odd and 2, 4, 6, 8 are even.) > > The page has this logic: > > select odd_even from T1 where location = '$location' > > if (odd_even == 'odd') > update T1 set odd_even = 'even' where location = > '$location' and > odd_even = 'odd'; > return '0'; > else > update T1 set odd_even = 'odd' where location = > '$location' and > odd_even = 'even'; > return '1'; > > But since each location calls the page in very quick > succession (a location > have have several parallel calls running - its a multi > threaded app), there > is a race condition. And at times several continuous calls return same > result (odd or even). > > How do I achieve thread safety? > > Please help. Its urgent. > > Thanks. > > Ravi. > > > > > > > |