View Issue Details

IDProjectCategoryView StatusLast Update
0003114Spring engineMac OS Xpublic2013-04-08 02:35
Reporterfoxtrot Assigned Tozerver  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Product Version89.0 
Summary0003114: I got multhreaded starting on OSX using pthread_getspecific() for TLS
DescriptionMT on mac was bugged because its TLS directly manipulates the FS/GS registers, speedy-tls uses linux-specific code to map memory, and xcode doesn't support gcc's __thread.

So, inside gmlcls.h, I changed thread-local storage from the assembly method into a pthread_getspecific() method. Since the only TLS is a single thread number integer, it's not that complicated. I simply replace get_threadnum with pthread getspecific() versions. getspecific() is very fast on darwin, so FS/GS hackery is not needed.

When playing, I can't see any widgets, lua crashes all the time, but at least spring-multithreaded starts I can click my commander and make him walk around...

my working code in gmlcls.h (hope this helps!):

# ifdef __APPLE__
// hackitude:
#undef set_threadnum
#undef get_threadnum
// we forgo all the segment register manipulation since pthread_setspecific is pretty fast on darwin.
#include <pthread.h>
// this class is instantiated statically so that keys are initialized exactly once per app run.
class CPthreadKeys {
public:
    pthread_key_t threadnum_key;
    CPthreadKeys(){
        pthread_key_create(&threadnum_key, NULL);
    }
};
static CPthreadKeys pthreadkeys;

inline int get_threadnum(void){
    return (int)(long) pthread_getspecific(pthreadkeys.threadnum_key);
}
inline void set_threadnum(int ThreadNumber){
    pthread_setspecific(pthreadkeys.threadnum_key, (void*) ThreadNumber);
}
#define gmlThreadNumber get_threadnum()
#else
// NON APPLE GML STUFF (aka the rest of it) goes here
#endif
Additional Informationosx 10.6, 32-bit kernel, 64 bit spring compile
TagsNo tags attached.
Attached Files
speedy-tls.cpp (Attachment missing)
Checked infolog.txt for Errors

Activities

zerver

2012-06-17 17:09

reporter   ~0008794

The speedy-tls docs here
http://www.kevinjhoffman.com/speedy-tls/
says it has been tested with OSX x86 (10.4, GCC 4.0.1)

Can you please check if the file I attached works any better? It is speedy-tls version 1.0, and I noticed the one in the spring repo had some slight differences.

zerver

2013-04-08 02:35

reporter   ~0010407

no feedback for a long time, and other users reported ASIM running on OSX without the suggested changes

Issue History

Date Modified Username Field Change
2012-06-13 05:59 foxtrot New Issue
2012-06-16 21:37 zerver Status new => assigned
2012-06-16 21:37 zerver Assigned To => zerver
2012-06-17 17:08 zerver File Added: speedy-tls.cpp
2012-06-17 17:09 zerver Note Added: 0008794
2012-06-17 17:09 zerver Status assigned => feedback
2013-04-08 02:35 zerver Note Added: 0010407
2013-04-08 02:35 zerver Status feedback => closed
2013-04-08 02:35 zerver Resolution open => no change required