Commit e1e0d699 authored by Brenden Tisler's avatar Brenden Tisler
Browse files

Deleted pthread_hello example in favor of pthread_demo

parent e7edc2e9
if(EXISTS "$ENV{HOME}/EMAC-SDK/example-projects/toolchain-selector.cmake")
include($ENV{HOME}/EMAC-SDK/example-projects/toolchain-selector.cmake)
else()
MESSAGE(FATAL_ERROR "ERROR: Toolchain selection could not be found at $ENV{HOME}/EMAC-SDK/example-projects/toolchain-selector.cmake")
endif()
### General Settings ###
cmake_minimum_required(VERSION 2.6)
project (p_hello)
add_executable(p_hello p_hello.c)
target_link_libraries(p_hello pthread)
######
### Define the remote directory for Qt Creator binary upload ###
file(WRITE "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "${REMOTE}")
######
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/pthread_hello DESTINATION share/qt-creator-examples)
INSTALL(TARGETS p_hello RUNTIME DESTINATION bin)
### Set variables to default values if not defined ###
if(DEFINED ARCH)
else()
SET(ARCH "def")
endif()
if(DEFINED REMOTE)
else()
SET(REMOTE "/tmp\n")
endif()
######
### Parse ARCH variable to get architecture ###
if(${ARCH} STREQUAL "x86")
SET(CMAKE_TOOLCHAIN_FILE ../toolchain.cmake.x86)
elseif(${ARCH} STREQUAL "armv5")
SET(CMAKE_TOOLCHAIN_FILE ../toolchain.cmake.armv5te)
elseif(${ARCH} STREQUAL "armv7")
SET(CMAKE_TOOLCHAIN_FILE ../toolchain.cmake.armv7a)
endif()
######
### General Settings ###
cmake_minimum_required(VERSION 2.6)
project (p_hello)
add_executable(p_hello p_hello.c)
target_link_libraries(p_hello pthread)
######
### Define the remote directory for Qt Creator binary upload ###
file(WRITE "${CMAKE_SOURCE_DIR}/QtCreatorDeployment.txt" "${REMOTE}")
######
/**
* @file p_hello.c
*
* Simple pthreads example application.
* Modified from code located here:
* http://www.cs.ucsb.edu/~tyang/class/pthreads/code/p_hello.c
*
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <pthread.h>
#define MAX_THREAD 100
typedef struct {
int id;
} parm;
void *hello(void *arg)
{
parm *p= (parm *)arg;
printf("Hello from node %d\n", p->id);
return (NULL);
}
int main(int argc, char* argv[])
{
int n, i;
pthread_t *threads;
pthread_attr_t pthread_custom_attr;
parm *p;
if (argc != 2)
{
printf ("Usage: %s n\n where n is no. of threads\n",argv[0]);
exit(1);
}
n = atoi(argv[1]);
if ((n < 1) || (n > MAX_THREAD))
{
printf ("The no of thread should between 1 and %d.\n",MAX_THREAD);
exit(1);
}
threads = (pthread_t *)malloc(n * sizeof(*threads));
pthread_attr_init(&pthread_custom_attr);
p = (parm *)malloc(sizeof(parm)*n);
/* Start up thread */
for (i=0; i<n; i++)
{
p[i].id=i;
pthread_create(&threads[i], &pthread_custom_attr, hello, (void *)(p + i));
}
/* Synchronize the completion of each thread. */
for (i=0; i < n; i++)
{
pthread_join(threads[i], NULL);
}
free(p);
exit(0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment