( See also beginning of [[Pthreads programming]] )
Most library functions are stateless — consider Math.
Most stateful library calls require manager object instantiation. This object is stateful. In java, some notable stateful language-level libraries include
– Class.forName() that automatically registers a JDBC driver
If there’s a syscall like setSystemTime(), it would be stateless because the C library doesn’t hold the state, which is held in the OS.
In C/C++, the most interesting, implicitly stateful library routines is malloc(). Invisible to you, the freelist is maintained not in any application object, nor in the OS, but in the C library itself. Malloc() is like an airline booking agent or IPO underwriter. It get s a large block and then divvies it up to your program. See the diagram on P188 [[C pointers and mem mgmt]]
The freelist keeper is known as “mem mgmt routine” in the “standard C-library”.
Another common stateful stdlib function is strtok(). It’s not a pure function. It remembers the “scanner position” from last call! The thread-safe version is strtok_r()