2011-07-11 14:07:16 +00:00
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#import <Foundation/NSThread.h>
|
2021-07-28 14:17:47 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <process.h>
|
|
|
|
#else
|
2011-07-11 14:07:16 +00:00
|
|
|
#include <pthread.h>
|
2021-07-28 14:17:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static NSThread *threadResult = nil;
|
2011-07-11 14:07:16 +00:00
|
|
|
|
2021-07-28 14:17:47 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
unsigned int __stdcall
|
|
|
|
#else
|
|
|
|
void *
|
|
|
|
#endif
|
|
|
|
thread(void *ignored)
|
2011-07-11 14:07:16 +00:00
|
|
|
{
|
2021-07-28 14:17:47 +00:00
|
|
|
threadResult = [NSThread currentThread];
|
|
|
|
return 0;
|
2011-07-11 14:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2021-07-28 14:17:47 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
HANDLE thr;
|
|
|
|
thr = (HANDLE)_beginthreadex(NULL, 0, thread, NULL, 0, NULL);
|
|
|
|
WaitForSingleObject(thr, INFINITE);
|
|
|
|
CloseHandle(thr);
|
|
|
|
#else
|
2015-03-31 09:45:40 +00:00
|
|
|
pthread_t thr;
|
|
|
|
pthread_create(&thr, NULL, thread, NULL);
|
2021-07-28 14:17:47 +00:00
|
|
|
pthread_join(thr, NULL);
|
|
|
|
#endif
|
|
|
|
PASS(threadResult != 0, "NSThread lazily created from native thread");
|
2015-03-31 09:45:40 +00:00
|
|
|
testHopeful = YES;
|
2021-07-28 14:17:47 +00:00
|
|
|
PASS((threadResult != 0) && (threadResult != [NSThread mainThread]),
|
2015-03-31 09:45:40 +00:00
|
|
|
"Spawned thread is not main thread");
|
2021-07-28 14:17:47 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
thr = (HANDLE)_beginthreadex(NULL, 0, thread, NULL, 0, NULL);
|
|
|
|
WaitForSingleObject(thr, INFINITE);
|
|
|
|
CloseHandle(thr);
|
|
|
|
#else
|
2015-03-31 09:45:40 +00:00
|
|
|
pthread_create(&thr, NULL, thread, NULL);
|
2021-07-28 14:17:47 +00:00
|
|
|
pthread_join(thr, NULL);
|
|
|
|
#endif
|
|
|
|
PASS(threadResult != 0, "NSThread lazily created from native thread");
|
|
|
|
PASS((threadResult != 0) && (threadResult != [NSThread mainThread]),
|
2015-03-31 09:45:40 +00:00
|
|
|
"Spawned thread is not main thread");
|
2011-07-11 14:07:16 +00:00
|
|
|
|
2015-03-31 09:45:40 +00:00
|
|
|
NSThread *t = [NSThread currentThread];
|
|
|
|
[t setName: @"xxxtestxxx"];
|
|
|
|
NSLog(@"Thread description is '%@'", t);
|
|
|
|
NSRange r = [[t description] rangeOfString: @"name = xxxtestxxx"];
|
|
|
|
PASS(r.length > 0, "thread description contains name");
|
2021-07-28 14:17:47 +00:00
|
|
|
|
|
|
|
PASS([NSThread threadPriority] == 0.5, "default thread priority is 0.5");
|
|
|
|
PASS([NSThread setThreadPriority:0.8], "change thread priority to 0.8");
|
|
|
|
PASS([NSThread threadPriority] == 0.8, "thread priority was changed to 0.8");
|
|
|
|
PASS([NSThread setThreadPriority:0.2], "change thread priority to 0.2");
|
|
|
|
PASS([NSThread threadPriority] == 0.2, "thread priority was changed to 0.2");
|
|
|
|
|
|
|
|
DESTROY(arp);
|
2015-03-31 09:45:40 +00:00
|
|
|
return 0;
|
2011-07-11 14:07:16 +00:00
|
|
|
}
|
|
|
|
|