I'm putting together a new module that has flags that need to be set as files are checked in and checked out. A flag will need to be set when a file is checked out.

I'm thinking the semaphore table would be good for this, seeing as it exists, and would seemingly exist for this purpose, but before I start using it I would like to know a little more about it. It seems to have been added in Drupal 6.16 without actually ever being used for anything, and I've not found any reference material on it!

Does cron clear it out after the expiration date has passed? Can I set zero for it to never expire? Does anyone have any links with any references to this table and how it should be used?

Comments

LaurentAjdnik’s picture

Hi,

this table is used by /includes/lock.inc (see http://api.drupal.org/api/drupal/includes--lock.inc).

Here's its purpose:

In most environments, multiple Drupal page requests (a.k.a. threads or processes) will execute in parallel. This leads to potential conflicts or race conditions when two requests execute the same code at the same time. [...] Any long-running operation that could potentially be attempted in parallel by multiple requests should try to acquire a lock before proceeding. By obtaining a lock, one request notifies any other requests that a specific opertation is in progress which must not be executed in parallel.

You can find calls to those lock_*() functions at a few places in the Core or modules.