If you try to call drupal_write_record('some_table', ...) after acquiring a lock on that table using db_lock_table('some_table'), you will get tons of errors having to do with locks on other tables. Here's an excerpt:
user warning: Table 'cache' was not locked with LOCK TABLES query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'schema' in /home/threexk/public_html/sandbox_d6_cvs/includes/cache.inc on line 26.
Test code that causes error:
$record = new StdClass();
$record->field1 = 'abc';
$record->field2 = 123;
Attached is (1) the module used to generate the test case, and (2) a copy/paste of all errors.
PHP memory limit: 5.2.6
In case it's relevant, my MySQL max_allowed_packet=16M and my PHP memory limit is 512MB. I tried upping the max_allowed_packet based on discussions of other issues, but that had no effect.