Hello, Mikhail Karpov, le dim. 08 nov. 2026 11:28:58 +0700, a ecrit: > On Sat, 7 Nov 2026 15:29:21 Samuel Thibault wrote: > > > > > Ok, then you can use a local struct port_bucket* variable to store the > > > > pointer while you are unsure whether the function will succeed, and > then > > > > either store to the global variable on success, or deallocate the > bucket > > > > on failure. > > > > > > We can keep the check on pager_port_bucket by first saving the result of > > > ports_create_bucket into a static variable, tmp_port_bucket. > > > > Why should that variable be static? > > This avoids the need to allocate and deallocate a new port_bucket every > time, > if pager_start_workers returns an error.
Ok, but I don't think it's worth it, for at least a couple important reasons: - static local variables are really a surprising thing for readers > > static variables local to functions really pose maintainability > > issues. > > Since the function is protected by a mutex, there shouldn't be any > issues I'm not talking about actual bugs, but about readability for people looking at the code. static local variables are really not a common thing (some people don't even really know how they work), and thus usually frowned upon. - if pager_start_workers fails, that would usually be for memory pressure reasons. Keeping the bucket allocated will not help. Better release all we can to try to let the recovery paths manage to work out even if they may need some allocations (e.g. to print an error message). > Also, what is the correct way to deallocate a port_bucket? Judging by > create-bucket.c, a single call to free (port_bucket) is not sufficient. It seems so, according to the hurd_ihash_destroy call at least. > Perhaps it would be worth adding a dedicated function for this in libports? Yes, it should have been done already :) It should probably assert that the ihash is already empty and the threadpool is empty. Samuel
