sema4shell is a set of tool allowing to access POSIX semaphores (atomic operations) in shell scripting.

WARRANTY :
This is given as is without any warranty, it could crash your computer, burn your house even nuke your planet.

On today computer most CPU has at least 2 virtual core, monothread programs are generally less efficient than well balanced threaded ones using different available resources in parallel.

To allow thread concurrency to do everything at the good time, depending on resources, they often depend on other thread tasks. Semaphore help to schedule tasks.

In this first (quick and dirty, without test or return value), there are five commands:

The semaphore name should not contain underscore and should start with a slash ('/').

==========!!!! WARNING !!!!===========
If a command segfault, verify first than you didn't unlink a semaphore before post/wait in your script.
(since sema4shell-0.2, error message should replace segfault)
The following line should show you some sem_wait waiting in this case:
ps ax | grep sem 
==========!!!! WARNING !!!!===========

Commands
There are five commands for now, I could add other later or make only one command (sema4shell) accepting arguments.

* sem_open  (create a named semaphore, with a start value (1 by default)).
Usage : sem_open "/semaphorename" 5
  Create a five tokens semaphore


* sem_wait  get a token or wait there is one free
Usage: sem_wait "/semaphorename"


* sem_post : free a token into the semaphore
usage: sem_post "/semaphorename"


* sem_unlink : close the semaphore and destroy it.
usage: sem_unlink "/semaphorename"


* sem_getvalue: display the actual value of the semaphore on stdout
Usage: sem_getvalue "semaphorename"


EXAMPLE :
* sample.sh
A commented example of How-To uses threads and semaphores.


This piece of software is released in THE GPL v2 license
© Popolon (popolon (a)_ popolon.org)
