[lug] Fwd: Simple counter?

Lori R lightningrose at gmail.com
Sat May 25 09:07:30 MDT 2013


>
>> Could you mmap a file and access as regular memory, then set it up
>> with pthreads and lock/unlock?
>
> Possibly, but if everything is in the same process, just use atomics.
> (They're a part of C++11 as well as C11, and gcc has supported them
> for years.)
>
> I inferred that the original poster was looking for more of a shell
> script level solution, but I might have been jumping to conclusions
> there...

I've not used atomics, but a mutex would be the usual solution for a
thread-safe implementation in a single process, and I also inferred that
Jeff, the OP, wanted something that would work with multiple processes.

My solution would be to use a text file for persistence, and a simple
program (without gotos ;)) that uses semaphores (you could think of
semaphores as system wide mutexs) to coordinate access to the file. This
solution assumes a local file mounted on a single computer. For multiple
nodes in a network, the earlier suggestion of using a database may be the
easiest solution.

-- 
Lori Reed
http://www.Lightning-Rose.com
http://som3000.sourceforge.net


On Sat, May 25, 2013 at 8:58 AM, Jeffrey S. Haemer <jeffrey.haemer at gmail.com
> wrote:

>
> I inferred that the original poster was looking for more of a shell
>> script level solution, but I might have been jumping to conclusions
>> there...
>
>
> The original poster is looking for an existing command that produces
> sequential integers, one per call.
>
> His motivation is a conviction that in the past thirty or forty years, *
> someone* must have contributed a standard tool/package that does this,
> coupled with embarrassment that he doesn't know it off the top of his head.
>
> A shell one-liner would be an okay substitute: something intermediate
> between "echo $RANDOM" and "echo 9<http://dilbert.com/strips/comic/2001-10-25/>"
> .  :-) (Thanks, Anthony.)
>
> Sure, there are edge-cases, some not obscure: "If we call it a bunch,
> can't the numbers get awfully big?" But geez, ....
>
> --
> Jeffrey Haemer <jeffrey.haemer at gmail.com>
> 720-837-8908 [cell], http://seejeffrun.blogspot.com [blog],
> http://www.youtube.com/user/goyishekop [vlog]
> *פרייהייט? דאס איז יאַנג דינען וואָרט.*
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20130525/60eb597f/attachment.html>


More information about the LUG mailing list