Advertisement
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 */
- cout<<"print_message_function";
- /* 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.
- */
- pthread_attr_init(&pthread_attributes);
- /* 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.
- */
- //sleep(5);
- /* 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) */
- //sleep(5);
- //exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement