hi guys
I met a problem when I was trying to use NSThread to sleep and wake up a thread. Because I am doing a porting job so I have to wirte some functions as interfaces between C++ and objective-c, and these functions are used to create, sleep, wake up and kill thread. I have implemented createThread() and killThread(), and they work well. But I don't know how to write sleepThread() and wakeupThread(), because the created thread should be sleeped and woke up by the main process but not the timer, so I am afraid the sleepForTimeInterval: and sleepUntilDate: won't work. could you guys give me a hand? Thanks a lot. And sorry for my poor English, I cant find enough info on my country's web site, and I hope you guys could understand what I am saying about.
and here is my code
class A //the c++ class
{
static void Func(void* p) { while(1) dosomething; }; //function in thread
}
@interface MacThread
{
NSThread* thread;
}
@end
@implementation MacThread
-(void)asThread
{
A::Func();
}
-(void) createThread: (unsigned int) stackSize
{
thread = [[NSThread alloc]initWithTarget:self selectorselector(asThread) object:nil];
[thread setStackSize:stackSize];
return;
}
-(void) startThread
{
[thread start];
}
-(void) sleepThread
{
//need your help
}
-(void) wakeupThread
{
//need your help
}
-(void) killThread
{
[thread cancel];
return;
}
@end
//followings are interfaces invoked in C++
void* cCreateThread(unsigned int stackSize)
{
MacThread *mThread = [MacThread alloc];
[mThread createThread:stackSize];
return (void*) mThread;
}
void cStartThread(void* thread)
{
MacThread *mThread = (MacThread*) thread;
[mThread startThread];
return;
}
void cSleepThread(void* thread)
{
//need your help
}
void cWakeupThread(void* thread)
{
//need your help
}
This is my first time posting here, thanks a lot again ^^
I met a problem when I was trying to use NSThread to sleep and wake up a thread. Because I am doing a porting job so I have to wirte some functions as interfaces between C++ and objective-c, and these functions are used to create, sleep, wake up and kill thread. I have implemented createThread() and killThread(), and they work well. But I don't know how to write sleepThread() and wakeupThread(), because the created thread should be sleeped and woke up by the main process but not the timer, so I am afraid the sleepForTimeInterval: and sleepUntilDate: won't work. could you guys give me a hand? Thanks a lot. And sorry for my poor English, I cant find enough info on my country's web site, and I hope you guys could understand what I am saying about.
and here is my code
class A //the c++ class
{
static void Func(void* p) { while(1) dosomething; }; //function in thread
}
@interface MacThread
{
NSThread* thread;
}
@end
@implementation MacThread
-(void)asThread
{
A::Func();
}
-(void) createThread: (unsigned int) stackSize
{
thread = [[NSThread alloc]initWithTarget:self selectorselector(asThread) object:nil];
[thread setStackSize:stackSize];
return;
}
-(void) startThread
{
[thread start];
}
-(void) sleepThread
{
//need your help
}
-(void) wakeupThread
{
//need your help
}
-(void) killThread
{
[thread cancel];
return;
}
@end
//followings are interfaces invoked in C++
void* cCreateThread(unsigned int stackSize)
{
MacThread *mThread = [MacThread alloc];
[mThread createThread:stackSize];
return (void*) mThread;
}
void cStartThread(void* thread)
{
MacThread *mThread = (MacThread*) thread;
[mThread startThread];
return;
}
void cSleepThread(void* thread)
{
//need your help
}
void cWakeupThread(void* thread)
{
//need your help
}
This is my first time posting here, thanks a lot again ^^