Click to See Complete Forum and Search --> : Need help with clone


Jalex
10-05-2003, 01:04 AM
I'm supposed to create threads with ansi C.. so can anybody explain me how to use clone?

I just find the syntax, but I need a full example... plz help!!!!!

bwkaz
10-05-2003, 02:30 PM
Wouldn't pthread_create() be much, much better than using clone()?

Considering the fact that either of them is ANSI C compatible, but clone() is Linux-only, while pthread_create() works across all POSIX platforms, I would lean toward using pthread_create() instead...

Jalex
10-05-2003, 04:27 PM
But the project is about not using pthread.h library.

You know just the libraries that ANSI C gives (like stdio.h, stdlib.h, time.h).

Thank you anyway....

bwkaz
10-06-2003, 07:15 PM
You can't use clone() with only the ANSI C headers.

clone() is declared in <unistd.h> (and also requires <sched.h>), which is not an ANSI header.

From the manpage for clone(2):

CONFORMING TO
The clone and sys_clone calls are Linux-specific and should not be used in programs
intended to be portable. For programming threaded applications (multiple threads
of control in the same memory space), it is better to use a library implementing
the POSIX 1003.1c thread API, such as the LinuxThreads library (included in
glibc2). See pthread_create(3).

This manual page corresponds to kernels 2.0.x, 2.1.x, 2.2.x, 2.4.x, and to glibc
2.0.x and 2.1.x. Now I won't complain if the assignment is to specifically use clone(), but if the assignment is to write an ANSI C program that uses threads, you'll be much better off with the libpthread.so library than you would with clone()...