diff options
| author | Clay Murray <clay.murray8@gmail.com> | 2020-07-11 18:22:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-11 18:22:56 -0600 |
| commit | 83eabe21408792ece7f8b7f4e35d357a520752ed (patch) | |
| tree | 4a9f9a79d44c716e99dcf6bbe88e4b2174fe8fb5 | |
| parent | c4067372dddbabd327cda1d4a821ef6b343a29b1 (diff) | |
Fix pthread_t on Macos.
From some testing with directly using C code, pthread_t on macos is 8 bytes.
This is my test code:
```
#include <assert.h>
#include <stdio.h>
#include <pthread.h>
void* PosixThreadMainRoutine(void* data)
{
// Do some work here.
for (int i = 0; i < 2000000000; i++) {
}
return NULL;
}
pthread_t LaunchThread()
{
// Create the thread using POSIX routines.
pthread_attr_t attr;
pthread_t posixThreadID;
int returnVal;
returnVal = pthread_attr_init(&attr);
assert(!returnVal);
returnVal = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
assert(!returnVal);
int threadError = pthread_create(&posixThreadID, &attr, &PosixThreadMainRoutine, NULL);
returnVal = pthread_attr_destroy(&attr);
assert(!returnVal);
if (threadError != 0)
{
// Report an error.
}
return posixThreadID;
}
int main() {
pthread_t t = LaunchThread();
void ** ret;
printf("%d, %d\n", sizeof(t), sizeof(pthread_t));
int val = pthread_join(t, ret);
printf("%d", val);
return 0;
}
```
running this on macos reports `8, 8`.
Then I made the proposed changes and errors I was having with threads completely went away.
| -rw-r--r-- | core/sys/unix/pthread_darwin.odin | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/core/sys/unix/pthread_darwin.odin b/core/sys/unix/pthread_darwin.odin index 9de64ead4..7f7f59189 100644 --- a/core/sys/unix/pthread_darwin.odin +++ b/core/sys/unix/pthread_darwin.odin @@ -14,11 +14,7 @@ PTHREAD_ONCE_SIZE :: 8; PTHREAD_RWLOCK_SIZE :: 192; PTHREAD_RWLOCKATTR_SIZE :: 16; -pthread_t :: opaque struct #align 16 { - sig: c.long, - cleanup_stack: rawptr, - _: [PTHREAD_SIZE] c.char, -}; +pthread_t :: opaque u64; pthread_attr_t :: opaque struct #align 16 { sig: c.long, |