Application counters in Linux? (and OSX?)

≡放荡痞女 提交于 2019-12-03 07:00:27
Parallel Universe

In addition to @user964970 comment/solution, I suggest making it OS agnostic.

Use an OS agnostic API, like ACE or BOOST, to create your own library, supplying a named-semaphore write-protected-counter, placed inside a named-shared-memory segment.

This should be your library's API :

long * createCounter(const char * name); // Create a counter
                                         // Will create a named semaphore and a named
                                         // shared memory segment, holding the counter     
                                         // value. Will return pointer to counter
long * getCounter(const char * name); // Get existing counter pointer
                                      // in the calling process' address space
long incCounter(const char * name);   // increment existing counter
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!