News:

Congratulations!
 You've won the News Item Lottery! Your prize? Reading this news item! :)

tpl freelist mutex locking incorrect

Started by jrs, January 20, 2026, 05:00:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jrs

I am working on a port of simutrans to openbsd and found their pthreads implementation was not happy with tpl/freelist_tpl.h, aborting due to an unlock with an unknown owner. While poking at the code trying to understand this I found the lock/unlock dance in tpl/freelist_tpl.h strange. Unlock was called twice. changing the first one to a lock allowed the game to run.

Index: simutrans/src/simutrans/tpl/freelist_tpl.h
--- simutrans/src/simutrans/tpl/freelist_tpl.h.orig
+++ simutrans/src/simutrans/tpl/freelist_tpl.h
@@ -170,7 +170,7 @@ class freelist_size_t (public)
#endif

#ifdef MULTI_THREAD
- pthread_mutex_unlock(&freelist_mutex);
+ pthread_mutex_lock(&freelist_mutex);
#endif

// putback to first node

One other small thing, this might just be an openbsd/clang peculiarity. but wanted to mention it just in case.
squirrel/squirrel/sqvm.h can not find a declaration for "va_list" I found it in stdarg.h

Index: simutrans/src/squirrel/squirrel/sqvm.h
--- simutrans/src/squirrel/squirrel/sqvm.h.orig
+++ simutrans/src/squirrel/squirrel/sqvm.h
@@ -2,6 +2,7 @@
 #ifndef _SQVM_H_
 #define _SQVM_H_
 
+#include <stdarg.h>
 #include "sqopcodes.h"
 #include "sqobject.h"
 #define MAX_NATIVE_CALLS 100




prissi

Well spotted, that should be indeed a lock unstead of unlock.

And the squirrel headers are patched, as we had to download squirrel verbatim. I am anyway trying to update simutrans to squirrel 3.2.


jrs

Salutes, And I just wanted to say thank you for providing a super positive experience for a first time poster with a one line diff.