Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <pthread.h>
- #define TEST_THREADS
- static const int MAX_ITER = 50*1000;
- void TestFork()
- {
- for(int i = 0; i < MAX_ITER; ++i) {
- pid_t p = fork();
- if (p) {
- int status;
- waitpid(p, &status, 0);
- }
- else
- exit(1);
- }
- }
- void *ThreadFunc( void *parg )
- {
- return NULL;
- }
- void TestThreads()
- {
- pthread_attr_t attr;
- pthread_attr_init( &attr );
- for(int i = 0; i < MAX_ITER; ++i) {
- pthread_t t;
- pthread_create( &t, &attr, ThreadFunc, NULL );
- void *status;
- int retCode = pthread_join( t, &status );
- }
- }
- int main() {
- #ifndef TEST_THREADS
- TestFork();
- #else
- TestThreads();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement