/ Check-in [2d2edfe5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix a race condition in the sorter code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | threads
Files: files | file ages | folders
SHA1: 2d2edfe58db101d42a96772b856e6e55b401aab6
User & Date: dan 2014-05-05 15:58:40
Context
2014-05-05
20:03
Add test file sort4.test, containing brute force tests for the multi-theaded sorter. check-in: 9cc364c4 user: dan tags: threads
15:58
Fix a race condition in the sorter code. check-in: 2d2edfe5 user: dan tags: threads
09:08
Add tests so that the "coverage-sorter" test permutation covers all branches in vdbesort.c. Fix a few minor problems in the same file. check-in: bde28b70 user: dan tags: threads
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbesort.c.

   987    987   /*
   988    988   ** Join all outstanding threads launched by SorterWrite() to create 
   989    989   ** level-0 PMAs.
   990    990   */
   991    991   static int vdbeSorterJoinAll(VdbeSorter *pSorter, int rcin){
   992    992     int rc = rcin;
   993    993     int i;
   994         -  for(i=0; i<pSorter->nTask; i++){
          994  +
          995  +  /* This function is always called by the main user thread.
          996  +  **
          997  +  ** If this function is being called after SorterRewind() has been called, 
          998  +  ** it is possible that thread pSorter->aTask[pSorter->nTask-1].pThread
          999  +  ** is currently attempt to join one of the other threads. To avoid a race
         1000  +  ** condition where this thread also attempts to join the same object, join 
         1001  +  ** thread pSorter->aTask[pSorter->nTask-1].pThread first. */
         1002  +  for(i=pSorter->nTask-1; i>=0; i--){
   995   1003       SortSubtask *pTask = &pSorter->aTask[i];
   996   1004       int rc2 = vdbeSorterJoinThread(pTask);
   997   1005       if( rc==SQLITE_OK ) rc = rc2;
   998   1006     }
   999   1007     return rc;
  1000   1008   }
  1001   1009   #else