Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if this will address <em>all</em> of your issues. But create a table with a Primary Key that isn't auto-generated. If possible, also declare the same column with some kind of check/rule that enforces that the column may only contain one possible value.</p> <p>You now have a table that can contain 0 or 1 rows. To obtain the "semaphore", insert a row into the table, with the single fixed PK value. If this insert succeeds, you own the semaphore. If the insert fails due to a primary key violation, then you didn't obtain the semaphore. The key is to <em>not</em> perform a preliminary check first - just attempt the insert.</p> <p>If your tech is so broken that it can't guarantee that the PK constraint will be maintained, then you seriously need to consider changing technology.</p> <p>If you <em>fail</em> to insert the row, then you can start regularly polling this table - at whatever intervals seem appropriate.</p> <hr> <p>The other alternative is to have the table have an autonumber PK column - when you want to obtain the semaphore, insert a row into the table. Then, query the table to locate the row with the lowest PK column value. If that row is <em>your</em> row, then you now own the semaphore. You still have to poll, but you effectively have a "reservation" recorded in this table.</p> <p>As with the previous case, once you have completed your semaphore protected work, you delete your row from the table. This second approach should be "fairer" (in that each process gains access in strict order of requests), but may look be messier in practice. It does rely on <em>all</em> processes staying "live".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload