[development] problems with shutdown function in search module
Khalid Baheyeldin
kb at 2bits.com
Mon Aug 6 14:24:50 UTC 2007
> I am not sure I understand the problem.
> If you want to make sure only one process runs at a time, we can use a
> locking
> mechanism like I do in one module:
>
> Making sure we get the lock prevents a race condition, a problem that make
> poormanscron.module currently unuseable (see link in code comment).
>
> /**
> * Implementation of hook_cron().
> */
> function hook_cron() {
> // Check if we have another instance of cron running.
> if (variable_get('hook_cron_running', 0)) {
> return;
> }
> // hook_cron is not already running.
> // See if we can get the lock before another process does.
> // Algorithm found here: http://drupal.org/node/43511.
> $result = db_query("UPDATE {variable} SET value = 'i:1;' WHERE name =
> 'hook_cron_running' AND value = 'i:0;'");
> if (db_affected_rows() != 1) {
> // We didn't get the lock. Another process outran us.
> watchdog('hook_cron', 'This cron process was outraced.');
> return;
> }
> // Do stuff here...
>
> // then, at the end:
> // Unlock.
> variable_set('hook_cron_running', 0);
> return;
> }
>
Wouldn't the second process be blocked until the first one completes,
instead
of returning immediately? There is no equivalent to Oracle's NOWAIT in MySQL
as far as I recall.
--
2bits.com
http://2bits.com
Drupal development, customization and consulting.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20070806/865aec38/attachment.htm
More information about the development
mailing list