haitao:
linux/c++:这样创建出来的是不是进程(而不是线程)?clone(clonefunc, newstack, CLONE_VM | CLONE_FS | CLONE_FILES……
[阅读: 1540] 2005-12-14 02:35:01
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void* (*fn)(void *), void *data)
{
long retval;
void **newstack;
int (*clonefunc)(void *) = (int (*)(void *))(fn);
newstack = (void **) malloc(STACKSIZE);
if (!newstack)
return -1;
newstack = (void **) (STACKSIZE + (char *) newstack);
*--newstack = data;
retval = clone(clonefunc, newstack,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD, data);
if (retval < 0) {
errno = -retval;
*thread = 0;
retval = -1;
} else {
*thread = retval;
retval = 0;
}
return retval;
}