51 assert(this->isExecuting ==
false);
93 int err = pthread_detach(*((pthread_t *) self->thread));
119 self->thread = calloc(1,
sizeof(pthread_t));
120 assert(self->thread);
132 int err = pthread_join(*((pthread_t *) self->thread), status);
142 int err = pthread_kill(*((pthread_t *) self->thread), signal);
177 int err = pthread_create(self->thread, NULL,
run, self);
181#pragma mark - Class lifecycle
213 .instanceSize =
sizeof(
Thread),
214 .interfaceOffset = offsetof(
Thread, interface),
215 .interfaceSize =
sizeof(ThreadInterface),
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define super(type, obj, method,...)
static void detach(Thread *self)
static void start(Thread *self)
static Thread * initWithFunction(Thread *self, ThreadFunction function, ident data)
static void join(Thread *self, ident *status)
static void cancel(Thread *self)
static void _kill(Thread *self, int signal)
static ident run(ident obj)
Wraps the user-specified ThreadFunction, providing cleanup.
static __thread Thread * _currentThread
static void dealloc(Object *self)
static Object * copy(const Object *self)
static void initialize(Class *clazz)
static Thread * init(Thread *self)
static Thread * currentThread(void)
ident(* ThreadFunction)(Thread *thread)
The function type for Thread execution.
void * ident
The identity type, similar to Objective-C id.
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Object is the root Class of The Objectively Class hierarchy.
void dealloc(Object *self)
Frees all resources held by this Object.
bool isExecuting
true when this Thread is executing, false otherwise.
Thread * initWithFunction(Thread *self, ThreadFunction function, ident data)
Initializes this Thread with the specified ThreadFunction and data.
void join(Thread *self, ident *status)
Wait for the specified Thread to terminate.
bool isDetached
true when this Thread has been detached, false otherwise.
ThreadFunction function
The Thread function.
bool isFinished
true when this Thread is finished, false otherwise.
bool isCancelled
true when this Thread has been cancelled, false otherwise.
void detach(Thread *self)
Daemonize this Thread.