a guest Feb 18th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <sched.h> /* Only necessary for sched_yield */
- #include "string.h"
- #include "iostream"
- using namespace std;
- void * print_message_function( void * VoidPtr )
- // char *message;
- // message = (char *) VoidPtr;
- // printf("%s", message);
- // fflush(stdout); /* Make sure we see it right away */
- /* If we wanted to return something, we would return a pointer
- * to the data that we wanted to return.
- * Instead of simply using return, we could also call
- * pthread_exit.
- return NULL;
- int main()
- pthread_attr_t pthread_attributes;
- //pthread_t progressThread;
- pthread_t thread1, thread2;
- char *message1 = "Hello";
- char *message2 = " World";
- cout<<"main print"<<endl;
- /* Populate attributes with defaults
- * If we wanted to customize this, we would probably
- * first set the defaults and then change as need.
- /* Start threads to write out messages
- * Please note that we are not checking the return,
- * this is something that you should figure out how
- * to do on your own.
- pthread_create( &thread1, &pthread_attributes,
- &print_message_function, (void *) message1);
- /* Provide N secs for completion (very bad idea to rely on this)
- * Use pthread_join instead, but you should learn to do this
- * on your own.
- /* Note that this time we don't pass the pthread_attributes
- * structure. Instead we pass NULL which tells POSIX threads
- * to just use the defaults.
- pthread_create(&thread2, NULL,
- &print_message_function, (void *) message2);
- /* Provide N secs for completion (very bad idea) */
RAW Paste Data