Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
56
Task/Concurrent-computing/C/concurrent-computing-1.c
Normal file
56
Task/Concurrent-computing/C/concurrent-computing-1.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
pthread_mutex_t condm = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||
int bang = 0;
|
||||
|
||||
#define WAITBANG() do { \
|
||||
pthread_mutex_lock(&condm); \
|
||||
while( bang == 0 ) \
|
||||
{ \
|
||||
pthread_cond_wait(&cond, &condm); \
|
||||
} \
|
||||
pthread_mutex_unlock(&condm); } while(0);\
|
||||
|
||||
void *t_enjoy(void *p)
|
||||
{
|
||||
WAITBANG();
|
||||
printf("Enjoy\n");
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *t_rosetta(void *p)
|
||||
{
|
||||
WAITBANG();
|
||||
printf("Rosetta\n");
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void *t_code(void *p)
|
||||
{
|
||||
WAITBANG();
|
||||
printf("Code\n");
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
typedef void *(*threadfunc)(void *);
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
pthread_t a[3];
|
||||
threadfunc p[3] = {t_enjoy, t_rosetta, t_code};
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
pthread_create(&a[i], NULL, p[i], NULL);
|
||||
}
|
||||
sleep(1);
|
||||
bang = 1;
|
||||
pthread_cond_broadcast(&cond);
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
pthread_join(a[i], NULL);
|
||||
}
|
||||
}
|
||||
11
Task/Concurrent-computing/C/concurrent-computing-2.c
Normal file
11
Task/Concurrent-computing/C/concurrent-computing-2.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *str[] = { "Enjoy", "Rosetta", "Code" };
|
||||
#pragma omp parallel for num_threads(3)
|
||||
for (int i = 0; i < 3; i++)
|
||||
printf("%s\n", str[i]);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue