Create_semaphore

sql

FUNCTION Create_semaphore(IN sname CHAR(31); IN snum INT) returns HANDLE;

Parameters

sname semaphore name
snum the count of threads the semaphore will be opened for

Since version:

6.1

Description

This procedure can be used only in the SQL commands.

This function creates a semaphore designated by the sname name (unless such semaphore exists) and returns its handle, that will be used in all thread operation with this semaphore.

If two threads call this function with the same sname, they will receive handle for the same semaphore - however these handles don't have to have identical value, because each thread must use its own handle get by this function.

The created semaphore will be opened for snum threads, which means that snum threads may execute the Wait_for_semaphore function without waiting, while any other threads will wait in this function until the Release_semaphore function is called by another thread. The most often values for snum are 0 (semaphore closed) or 1 (semaphore opened for one thread). The snum value is used only for the first thread calling the Create_Semaphore function with some name. If the function returns handle for an existing semaphore, snum is ignored.

See more about thread synchronization here.

Function value

This function returns the handle of the created semaphore, or 0 when unsuccessful.

See