RE: Another Semaphore question.

2001-05-06 Thread guy keren


On Sun, 6 May 2001, Oded Arbel wrote:

 I don't know of any other really good Linux programming books out there,
 but if you need something to read to get you started with API programming
 in Linux, or want a backup sitting on your desktop - I can recommend it.

this book sohuld be used not necessarily to _learn_ the API. it should be
used when you want to make sure your code is portable to other unices, and
that you've covered all cases. it covers things that man pages miss or
don't explain clearly, and more then once i've used it to make sure a
piece of code is written properly. there are various cases where you write
code and it looks like it works, and then you start hitting bugs that
cannot be reproduced, and after checking with steven's various books, you
find you did something wrong, you fix it - and see those non-reproduceable
bugs go away.

and in those cases, you only need to read 2-3 pages from the book, so you
(hopefully) don't manage to get bored yet.

--
guy

For world domination - press 1,
 or dial 0, and please hold, for the creator. -- nob o. dy


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-06 Thread guy keren


  Yes. This is one of the problems with semaphores. BTW, why not using file
  locking instead of it? It has much cleaner and richer semantics and almost
  none of the problems semaphores have.

not terribly good portability, according to
/usr/src/linux/Documentatino/mandatory.txt , for mandatory locks?
advisory locks can be used, but then you only have a single such lock
available per file. if you need to use several locks, you need to keep
several files open, and since there's a limit on file descriptors per
process, this is not scaleable.

as to oded's reply:

 I don't think its an option I have for the current implementation - it's
 file IO, and should be much slower, right ?

well, i'm not sure that usage of locks performs any file I/O (after all,
all the locks data is kept in memory, not on disk, as this is NOT
persistent data). however, looking at the kernel's sources, it seems that
at least the implementation of mandatory locks would be less efficient
then that of semaphores. the locks on a file are kept as a linked list,
and sometimes get traversed - thus, if you have many locks active on a
single file, that'll be less efficient then using semaphores.

as for advisory locks (handled using the flock() syscall) - there is also
a linked list of locks kept on a file. however, if you'll only use
exclusive locks, there could be only one lock in this list at any given
time. and there is no file I/O during those operations.

--
guy

For world domination - press 1,
 or dial 0, and please hold, for the creator. -- nob o. dy


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-06 Thread Oded Arbel

On Sun, 6 May 2001, guy keren wrote:

  I don't think its an option I have for the current implementation - it's
  file IO, and should be much slower, right ?

 well, i'm not sure that usage of locks performs any file I/O (after all,
 all the locks data is kept in memory, not on disk, as this is NOT
 persistent data). however, looking at the kernel's sources, it seems that
 at least the implementation of mandatory locks would be less efficient
 then that of semaphores. the locks on a file are kept as a linked list,
 and sometimes get traversed - thus, if you have many locks active on a
 single file, that'll be less efficient then using semaphores.

 as for advisory locks (handled using the flock() syscall) - there is also
 a linked list of locks kept on a file. however, if you'll only use
 exclusive locks, there could be only one lock in this list at any given
 time. and there is no file I/O during those operations.

Thanks.
I'll think about, but I don't think I'll change from semaphores just yet.
I don't like the idea of creating temp files for locks, and I can't lock
against an existing file, since I sometimes need to create several
different locks in the same application, and w/o creating files, this
mechanism would need to be way too complicated.

Oded



=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-06 Thread Stanislav Malyshev a.k.a Frodo

gk not terribly good portability, according to
gk /usr/src/linux/Documentatino/mandatory.txt , for mandatory locks?
gk advisory locks can be used, but then you only have a single such lock
gk available per file. if you need to use several locks, you need to keep

What? You sure should use advisory ones, for if you thought about
semaphores, you are surely writing cooperative application. But advisory
lock can be set one per each _byte_ of the file, not one per file. And
since you are not limited by the filesize, this gives you, IIRC, about 4G
of locks per file. Each lock, though, wastes certain amount of kernel
memory, so you should not use all of them ;)

gk several files open, and since there's a limit on file descriptors per
gk process, this is not scaleable.

Frankly, how many locks do you need? Thousands? Billions? Most probably
two or three, really.

gk well, i'm not sure that usage of locks performs any file I/O (after all,

No, it does not. As for speed - this is very OS-dependant. I remember
seeing some numbers in Stevens, but I don't remember what they told. IIRC,
for Linux it's pretty much the same.

gk and sometimes get traversed - thus, if you have many locks active on a
gk single file, that'll be less efficient then using semaphores.

Well, that's true - but really,, how many apps except databases (where
semaphores are irrelevant anyway, since you need to lock real files) have
more than ten locks?
-- 
[EMAIL PROTECTED]  \/  There shall be counsels taken
Stanislav Malyshev  /\  Stronger than Morgul-spells
phone +972-3-9316425/\  JRRT LotR.
http://sharat.co.il/frodo/  whois:!SM8333


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-06 Thread Stanislav Malyshev a.k.a Frodo

OA I don't think its an option I have for the current
OA implementation - it's file IO, and should be much slower, right
OA ?

Wrong. Record locking has nothing to do with file I/O - it is done
entirely in memory.

-- 
[EMAIL PROTECTED]  \/  There shall be counsels taken
Stanislav Malyshev  /\  Stronger than Morgul-spells
phone +972-3-9316425/\  JRRT LotR.
http://sharat.co.il/frodo/  whois:!SM8333


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-06 Thread Stanislav Malyshev a.k.a Frodo

OA I'll think about, but I don't think I'll change from semaphores just yet.
OA I don't like the idea of creating temp files for locks, and I can't lock

Actually, cleaning temp file is by far easier than cleaning semaphore.
Especially if your app can be killed any moment.

OA against an existing file, since I sometimes need to create several
OA different locks in the same application, and w/o creating files, this
OA mechanism would need to be way too complicated.

Why? Create one file and lock bytes 1, 2 and 3. BTW, semaphores are much
more scarce resource than files - they are system-wide and defaults are
pretty low on them.

-- 
[EMAIL PROTECTED]  \/  There shall be counsels taken
Stanislav Malyshev  /\  Stronger than Morgul-spells
phone +972-3-9316425/\  JRRT LotR.
http://sharat.co.il/frodo/  whois:!SM8333


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-04 Thread oron

On 03-May-2001 Stanislav Malyshev a.k.a Frodo wrote:
 OA and then leave it lying around and exit the process - will it stay
 OA in the system when no current process uses it ?
 
 Yes. This is one of the problems with semaphores. BTW, why not using

This is not a PROBLEM but a FEATURE. All Sys-V IPC (semaphores,
message queues, shared memory) outlive their creators.

You are completely right that if this behavior isn't desired in the
application, we should choose other IPC mechanism (that's why we have so
many of them).

However, semaphore aren't being used just for Mutual-Exclusion problems.
A classical counter example is producer-consumer that aren't running
continuously.


Oron Peled Voice/Fax: +972-4-8228492
[EMAIL PROTECTED]  http://www.actcom.co.il/~oron

There's nothing wrong with Windows 2000...
   ...that Linux can't fix


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-04 Thread Stanislav Malyshev a.k.a Frodo

 This is not a PROBLEM but a FEATURE. All Sys-V IPC (semaphores,
 message queues, shared memory) outlive their creators.

Wrong. Shared memory can be pre-deleted, so that it is removed when last
process is detached. Just like files. Semaphores can not. In fact, there's
no good way to insure that application cleans up its semaphores on exit.
If you know one, you are more than welcome to share.

 However, semaphore aren't being used just for Mutual-Exclusion problems.
 A classical counter example is producer-consumer that aren't running
 continuously.

Well, in fact in most cases sempahores are used for mutual exclusion or
usage control (something like does anyone uses this resource or can I
mess with it?). From my experience, file locks work way better in this
case.

-- 
[EMAIL PROTECTED]  \/  There shall be counsels taken
Stanislav Malyshev  /\  Stronger than Morgul-spells
phone +972-3-9316425/\  JRRT LotR.
http://sharat.co.il/frodo/  whois:!SM8333


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Another Semaphore question.

2001-05-03 Thread Oded Arbel


Hi list.

One more semaphore question if you please - if I create a semaphoer set,
and then leave it lying around and exit the process - will it stay in the
system when no current process uses it ?
If so - what does it take to clear it from the system : loging out ? going
to runlevel 1 ? rebooting ?

Oded



=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-03 Thread Stanislav Malyshev a.k.a Frodo

OA One more semaphore question if you please - if I create a semaphoer set,
OA and then leave it lying around and exit the process - will it stay in the
OA system when no current process uses it ?

Yes. This is one of the problems with semaphores. BTW, why not using file
locking instead of it? It has much cleaner and richer semantics and almost
none of the problems semaphores have.

OA If so - what does it take to clear it from the system : loging out ? going
OA to runlevel 1 ? rebooting ?

Or you do RMID operation on it (btw, you can RMID used semaphore too, so
you will need to check if it's in use manually), or reboot.
-- 
[EMAIL PROTECTED]  \/  There shall be counsels taken
Stanislav Malyshev  /\  Stronger than Morgul-spells
phone +972-3-9316425/\  JRRT LotR.
http://sharat.co.il/frodo/  whois:!SM8333


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




Re: Another Semaphore question.

2001-05-03 Thread Shaul Karl

 
 Hi list.
 
 One more semaphore question if you please - if I create a semaphoer set,
 and then leave it lying around and exit the process - will it stay in the
 system when no current process uses it ?
 If so - what does it take to clear it from the system : loging out ? going
 to runlevel 1 ? rebooting ?
 
 Oded
 


ipcs and then ipcrm ?
-- 

Shaul Karl [EMAIL PROTECTED]



=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]