text stringlengths 192 6.24k | label int64 0 1 |
|---|---|
#include <pthread.h>
struct element
{
int value;
pthread_mutex_t lock;
};
struct element* buffer;
int max_buffer_size;
int count;
int fd;
pthread_mutex_t fileLock;
int in;
int out;
pthread_mutex_t proLock;
int val=0;
void * producerFunction(void* args)
{
int i;
char name[100];
spri... | 1 |
#include <pthread.h>
static pthread_t ui_thread;
static pthread_mutex_t ui_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t ui_list_mutex = PTHREAD_MUTEX_INITIALIZER;
static int initialized;
static struct generic_queue_head ui_msg_queue;
static int text_msg(int level, const char ... | 0 |
#include <pthread.h>
void keepBusy( double howLongInMillisec );
pthread_mutex_t mutex;
pthread_mutexattr_t attr;
pthread_cond_t cv;
int balance;
} Account;
Account* create_account();
void deposit( Account* a, int dep );
void withdraw( Account* a, int draw );
void multiple_deposits( Account... | 1 |
#include <pthread.h>
pthread_mutex_t mutex, mutex2, mutex3;
time_t init_time;
int cnt, cnt2;
void espera_activa( int tiempo) {
time_t t;
t = time(0) + tiempo;
while(time(0) < t);
}
int get_the_time(){
return (time(0) - init_time);
}
void *tareaA( void * args) {
printf("%d::A::voy a... | 0 |
#include <pthread.h>
int counter = 0;
pthread_mutex_t my_mutex[5];
void *test_mutex(void *tid)
{
int thread_id;
int rnd;
int *tt;
tt = tid;
thread_id = (int) *tt;
rnd = rand() % 5;
sleep(rnd);
if (thread_id > 0) {
pthread_mutex_lock(&my_mutex[thread_id]);
}
... | 1 |
#include <pthread.h>
void testerFunc (int argc, char *argv[]);
void *threadAction(void *pointer);
void printInfo(struct timespec begin, struct timespec end);
void add_synC(long long *pointer, long long value);
int iterations = 1;
int numThreads = 1;
int syncMethod = 0;
int opt_yield = 0;
int tes... | 0 |
#include <pthread.h>
pthread_mutex_t mutex_b;
pthread_mutex_t en_espera_h;
pthread_mutex_t en_espera_m;
pthread_cond_t hombres_filtro;
pthread_cond_t mujeres_filtro;
int estado;
int fila_hombres = 0;
int fila_mujeres = 0;
int total_p = 0;
void entrar_bano(int num, pthread_mutex_t *mutex, pthread... | 1 |
#include <pthread.h>
volatile int flags[10];
volatile int wait[10];
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void *DoWork1(void *threadid)
{
flags[0] = flags[0] + 1;
wait[0] = 0;
pthread_exit(0);
}
void *DoWork2(void *threadid)
{
pthread_mutex_lock (&mutex);
f... | 0 |
#include <pthread.h>extern void __VERIFIER_error();
unsigned int __VERIFIER_nondet_uint();
static int top = 0;
static unsigned int arr[5];
pthread_mutex_t m;
_Bool flag = 0;
void error(void)
{
ERROR:
__VERIFIER_error();
return;
}
void inc_top(void)
{
top++;
}
void dec_top(void)
{
top--;
}
int get_top(void... | 1 |
#include <pthread.h>
struct range
{
long start;
long end;
};
float numbers[1000000];
double sum=0.0;
pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
void *sumNumbersInRange(void *range);
void timeval_print(struct timeval *tv)
{
printf("%06ld microseconds\\n", tv->tv_usec);
}
int ... | 0 |
#include <pthread.h>
struct sin_pkt *
sin_pkt_ctor(struct sin_pkt_zone *my_zone, int zone_idx,
struct netmap_ring *my_ring, int *e)
{
struct sin_pkt *pkt;
pkt = malloc(sizeof(struct sin_pkt));
if (pkt == 0) {
_SET_ERR(e, ENOMEM);
return (0);
}
memset(pkt, '\\... | 1 |
#include <pthread.h>
pthread_mutex_t sharedElementMutex;
pthread_cond_t canConsumeCondition;
int isEmpty = 1;
int isDone = 0;
int numOfThreads = 0;
int rc = 0;
struct _linked_list* lst;
int value;
struct _list_node* next;
struct _list_node* prev;
}list_node;
list_node* head;
list_no... | 0 |
#include <pthread.h>
int removeProduct(struct ringBuffer * buffer){
printf("\\n+--------------------------------------+\\n");
printf("+ CONSUMING AND INSERTING PRODUCT +\\n");
printf("+--------------------------------------+\\n");
int currentOut = buffer->out;
struct product * dat... | 1 |
#include <pthread.h>
pthread_mutex_t mutex;
pthread_t tidP,tidC;
sem_t full,empty;
int counter;
int buffer[10];
void initialise()
{
pthread_mutex_init(&mutex,0);
sem_init(&full,1,0);
sem_init(&empty,1,10);
counter=0;
}
void write(int item)
{
buffer[counter++]=item;
}
in... | 0 |
#include <pthread.h>
struct msg {
struct msg *m_next;
void *private_data;
};
struct job {
struct job *j_next;
struct job *j_prev;
pthread_t j_id;
};
struct msg *workq;
pthread_cond_t qready = PTHREAD_COND_INITIALIZER;
pthread_mutex_t qlock = PTHREAD_MUTEX_INITIALIZER;
void
process_msg(v... | 1 |
#include <pthread.h>
void philosopher_fn(void*);
pthread_mutex_t mutex_arr[5];
sem_t four_chairs;
int main()
{
int i=0;
pthread_t threads[5];
for(i=0;i<5;i++){
pthread_mutex_init(&mutex_arr[i],0);
}
sem_init(&four_chairs,0,4);
i = 0;
while(i<5){
... | 0 |
#include <pthread.h>
pthread_mutex_t lock;
struct timeval start_time,end_time;
float seq_thread_func(long int size)
{
int k=0;
pthread_mutex_lock(&lock);
long int blockSize=(long int)(20*1000000)/size;
char *mem1;
char *mem2;
mem1=malloc(blockSize*size);
mem2=malloc(block... | 1 |
#include <pthread.h>
void InitBasicQueue(int size)
{
CIRCLEQ_INIT(&head);
CIRCLEQ_INIT(&rq_head);
pthread_mutex_init(&lock, 0);
}
void BasicEnqueue(void* task)
{
struct basicentry* n = (struct basicentry*) malloc(sizeof(struct basicentry));
n->elem = task;
pthread_mutex_lock(&lock);
CIRCLE... | 0 |
#include <pthread.h>
void thread_listen() {
int sockfd, income_sockfd;
struct sockaddr_in local, income;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("Listening socket");
exit(1);
}
socket_reuse(sockfd);
local.sin_family = AF_INE... | 1 |
#include <pthread.h>
int count = 0;
pthread_mutex_t count_mutex;
pthread_cond_t count_threshold_cv;
void *inc_count(void *idp)
{
int j,i;
double result=0.0;
long my_id = (long)idp;
for (i=0; i < 10; i++) {
pthread_mutex_lock(&count_mutex);
count++;
if (count ==... | 0 |
#include <pthread.h>
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t C = PTHREAD_COND_INITIALIZER;
int customer_count = 0;
int chair_count = 5;
int flag_sleeping=0;
int max_customer_count = 10;
int total = 10;
pthread_cond_t call_customer=PTHREAD_COND_INITIALIZER;
pthread_con... | 1 |
#include <pthread.h>
struct handler_list {
void (*handler)(void);
struct handler_list * next;
};
static pthread_mutex_t pthread_atfork_lock = PTHREAD_MUTEX_INITIALIZER;
static struct handler_list * pthread_atfork_prepare = 0;
static struct handler_list * pthread_atfork_parent = 0;
static stru... | 0 |
#include <pthread.h>
int ca = 0;
int ce = 0;
int ci = 0;
int co = 0;
int cu = 0;
int c;
FILE * fp;
pthread_t h[3];
pthread_mutex_t candl;
pthread_mutex_t cande;
int cuentaLineas(char * ptr);
void contador(void * ptr);
int main(int argc, char **argv){
char * nomarch;
nomarch = argv[1];... | 1 |
#include <pthread.h>
pthread_mutex_t read_mutex, write_mutex;
void* write() {
char *ret;
FILE *f;
char str[20];
pthread_mutex_lock(&write_mutex);
sleep(5);
pthread_mutex_lock(&read_mutex);
printf("\\nFile Locked. Please Enter the content to be written in the file...\\n");
scanf("%s", s... | 0 |
#include <pthread.h>
pthread_mutex_t stderr_lock = PTHREAD_MUTEX_INITIALIZER;
static void (*die_cb)() = 0;
static int suppress = s_none;
void merr_suppress(int s) {
suppress = s;
}
void die_set_cb(void (*cb)(int)) {
die_cb = cb;
}
void fprintfp(FILE *fd, const char *fmt, ...) {
va_list ap... | 1 |
#include <pthread.h>
float pougre=0;
pthread_mutex_t lemutex;
void* oddsum(void* arg)
{
int plo;
for (plo=1 ; plo<=100 ; plo+=2) {
pthread_mutex_lock(&lemutex);
pougre+=sqrt(plo);
pthread_mutex_unlock(&lemutex);
}
pthread_exit(0);
}
void* evensum(void* arg)
{
int iougre;
for (iougr... | 0 |
#include <pthread.h>
int tid;
pthread_mutex_t * p2c;
pthread_mutex_t * c2p;
int numVerts;
int numThr;
int** M_prev;
int** M_curr;
} pt_mat;
void *Thr(void *thrargs) {
struct pt_mat *mat;
mat = (struct pt_mat *)thrargs;
int t = (mat->tid);
int i,j,k;
for(k=0; k<(mat->numVer... | 1 |
#include <pthread.h>
void ft_print_maps_size(void)
{
ft_putstr("\\033[33m");
ft_putstr("Tiny size: ");
ft_putnbr(g_env.tiny_size);
ft_putstr(" || alloc: ");
ft_putnbr(g_env.tiny_alloc_size);
ft_putchar('\\n');
ft_putstr("Small size: ");
ft_putnbr(g_env.small_size);
ft_putstr(" || alloc: "... | 0 |
#include <pthread.h>
pthread_mutex_t mutexA = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutexB = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutexC = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutexD = PTHREAD_MUTEX_INITIALIZER;
void *thread_func1(void *tmp)
{
while(1)
{
pthread_mutex_lock(&m... | 1 |
#include <pthread.h>
int counter = 0;
pthread_mutex_t my_mutex[5];
pthread_mutex_t my_cond_mutex;
pthread_cond_t cond;
void *test_mutex(void *tid)
{
int thread_id;
int rnd;
int *tt;
tt = tid;
thread_id = (int) *tt;
rnd = rand() % 3;
sleep(rnd);
pthread_mutex_lock(&my_cond_m... | 0 |
#include <pthread.h>
unsigned long Flag_Count;
unsigned long Flag_Range;
unsigned long Flag_Threads;
unsigned long Threads_Completed;
pthread_mutex_t Lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t Job_Done = PTHREAD_COND_INITIALIZER;
void emit_help(void);
void *worker(void *unused);
int m... | 1 |
#include <pthread.h>
extern struct FileList* root;
void* upload(void* arg)
{
int clntSock = ((struct connection*)arg)->clntSock;
struct sockaddr_in clntAddr = ((struct connection*)arg)->clntAddr;
int clntAddrLen = ((struct connection*)arg)->clntAddrLen;
struct FileList* file;
char buffer[MAX... | 0 |
#include <pthread.h>
pthread_mutex_t lock;
int pid_map[350 +1];
int last;
int allocate_map(void)
{
int i;
for (i = 300; i < 350 +1; i++)
pid_map[i] = 0;
last = 300;
return 1;
}
int allocate_pid(void)
{
int new_pid, i;
int map_range = (350 - 300);
if (last > 350 ||... | 1 |
#include <pthread.h>
struct signalfd_context {
int fd;
int flags;
struct signalfd_context *next;
};
static struct signalfd_context *signalfd_contexts;
pthread_mutex_t signalfd_context_mtx = PTHREAD_MUTEX_INITIALIZER;
struct signalfd_context *
get_signalfd_context(int fd, bool create_new)... | 0 |
#include <pthread.h>
pthread_mutex_t lock;
int value;
}SharedInt;
sem_t sem;
SharedInt* sip;
void *functionWithCriticalSection(int* v2) {
pthread_mutex_lock(&(sip->lock));
sip->value = sip->value + *v2;
int i = 0;
while(i < 3) {
pthread_mutex_unlock(&(sip->lock))... | 1 |
#include <pthread.h>extern void __VERIFIER_error() ;
unsigned int __VERIFIER_nondet_uint();
static int top=0;
static unsigned int arr[(800)];
pthread_mutex_t m;
_Bool flag=(0);
void error(void)
{
ERROR:
__VERIFIER_error(); return;
}
void inc_top(void)
{
top++;
}
void dec_to... | 0 |
#include <pthread.h>
pthread_mutex_t *mut;
int writers;
int readers;
int waiting;
pthread_cond_t *writeOK, *readOK;
} rwl;
rwl *initlock (void);
void readlock (rwl *lock, int d);
void writelock (rwl *lock, int d);
void readunlock (rwl *lock);
void writeunlock (rwl *lock);
void... | 1 |
#include <pthread.h>
int create_cyclic_int_buffer(struct cyclic_int_buffer *cyclic_buffer, size_t capacity) {
cyclic_buffer->internal_capacity = capacity + 1;
cyclic_buffer->read_idx = 0;
cyclic_buffer->write_idx = 0;
cyclic_buffer->is_empty = 1;
cyclic_buffer->is_full = 0;
pthread_m... | 0 |
#include <pthread.h>
struct foo *fh[29];
pthread_mutex_t hashlock = PTHREAD_MUTEX_INITIALIZER;
struct foo {
int f_count;
pthread_mutex_t f_lock;
int f_id;
struct foo *f_next;
};
struct foo *foo_alloc(int id) {
struct foo *fp;
int idx;
if((fp = (struct foo *)mallo... | 1 |
#include <pthread.h>
struct mpd_connection *conn = 0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void InitMPC(void)
{
FILE * pFile;
pFile = fopen (ONLINE_LIST_PATH,"wb");
if (pFile==0)
{
perror ("nd InitMPC create online.lst.m3u Error\\n");
}
fclose(pFile);
new_connection(&co... | 0 |
#include <pthread.h>
char share_buffer[5];
int curr=-1;
int empty=0;
int full=5;
pthread_mutex_t share_mutex;
sem_t non_empty,non_full;
void * consumer_func(void * whichone)
{
int position;
char data;
char *who;
who = (char *)whichone;
printf("%s: Starting...\\n",who);
while(1)... | 1 |
#include <pthread.h>
static pthread_mutex_t *lockarray;
static void lock_callback(int mode, int type, char* file, int line) {
(void) file;
(void) line;
if (mode & CRYPTO_LOCK) {
pthread_mutex_lock(&(lockarray[type]));
}
else {
pthread_mutex_unlock(&(lockarray[type]));
}
}
static un... | 0 |
#include <pthread.h>
static char pool[5 * STRING_SIZE];
static int inUse[5];
static unsigned int inUseCount;
static pthread_mutex_t mutex;
static pthread_cond_t condition;
int initStringPool()
{
int i, ret;
pthread_mutexattr_t attr;
inUseCount = 0;
ret = initRTMutexAttr(&attr);
if(ret !... | 1 |
#include <pthread.h>
void *iniciarAplicacao() {
int i;
ic_num = 0;
for (i = 0; i < MAX_PS; i++)
ps[i] = -1;
int te, tr;
pthread_t threadReceberPacotes;
tr = pthread_create(&threadReceberPacotes, 0, receberPacotes, 0);
if (tr) {
printf("ERRO: impos... | 0 |
#include <pthread.h>
pthread_mutex_t the_mutex;
pthread_cond_t condc, condp;
int buffer = 0;
void *producer(void *ptr)
{
int i;
for (i = 1; i <= 1000000000; i++) {
pthread_mutex_lock(&the_mutex);
while(buffer != 0) {
pthread_cond_wait(&condp, &the_mutex);
... | 1 |
#include <pthread.h>
struct foo *fh[29];
pthread_mutex_t hashlock = PTHREAD_MUTEX_INITIALIZER;
struct foo{
int f_count;
pthread_mutex_t f_lock;
int f_id;
struct foo *f_next;
};
struct foo* foo_alloc(int id)
{
struct foo *fp;
int idx;
if((fp = malloc(sizeof(struct foo))) !=0){
fp->f_... | 0 |
#include <pthread.h>
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_t tid;
int maxNum;
int iter;
int sum;
void *func(void *arg)
{
(char *)arg;
while (1)
{
pthread_mutex_lock(&lock);
iter++;
sum += iter;
if(maxNum < iter)
{
... | 1 |
#include <pthread.h>
int quitflag;
sigset_t mask;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t waitloc = PTHREAD_COND_INITIALIZER;
static void sig_int(int signo){
printf("catch sigint:%ld\\n",(unsigned long)pthread_self());
}
void *thr_fn(void *arg){
int err, signo;
signa... | 0 |
#include <pthread.h>
struct cell {
int player_id;
pthread_mutex_t cell_lock;
};
struct field {
pthread_rwlock_t field_lock;
struct cell* cells;
};
int dim = 0;
int min_players;
int player_count = 0;
int delay = 0;
int join_countdown = 10000;
struct field* field;
void req... | 1 |
#include <pthread.h>
int number;
pthread_mutex_t mutex;
void* funcA_num(void* arg)
{
for(int i=0; i<10000; ++i)
{
pthread_mutex_lock(&mutex);
int cur = number;
cur++;
number = cur;
printf("Thread A, id = %lu, number = %d\\n", pthread_self(), num... | 0 |
#include <pthread.h>
void pipeline_link_pipe_init(struct pipeline_link_pipe* link, unsigned int buffer_size) {
pipeline_link_init((struct pipeline_link*)link,
pipeline_link_pipe_push,
pipeline_link_pipe_pop,
pipeline_link_pipe_is_full,
pipeline_link_pipe_is_empty,
pipeline_link_pipe_i... | 1 |
#include <pthread.h>
pthread_mutex_t barrier;
pthread_cond_t go;
int numWorkers;
int numArrived = 0;
void Barrier() {
pthread_mutex_lock(&barrier);
numArrived++;
if (numArrived == numWorkers) {
numArrived = 0;
pthread_cond_broadcast(&go);
} else
pthread_cond_wait(&go, &barr... | 0 |
#include <pthread.h>
static char* output_string = 0;
static pthread_mutex_t output_lock;
static int initialized = 0;
static pthread_t thread;
static void* query_brightness_thread() {
if( output_string == 0 ) {
output_string = calloc( 32, sizeof(char) );
}
while( initia... | 1 |
#include <pthread.h>
pthread_mutex_t mutex;
void *myfunc(void *arg)
{
pthread_mutex_lock(&mutex);
pthread_mutex_unlock(&mutex);
return 0;
}
int main()
{
pthread_t t;
pthread_mutex_init(&mutex, 0);
pthread_create(&t, 0, myfunc, 0);
int ret;
if ((ret = fork()) > 0) {
wait(0);
... | 0 |
#include <pthread.h>
void *raw_socket(void *pParam){
struct frame_queue *temp;
int sockfd,on = 1;
struct sniff_ip *iph;
int len,iph_len;
struct sockaddr_in dst_sin;
ssize_t size;
int i;
unsigned char *data;
unsigned short recv_sum,calc_sum;
char message[150];
sockfd = socket... | 1 |
#include <pthread.h>
struct foo * fh[29];
pthread_mutex_t hashlock = PTHREAD_MUTEX_INITIALZER;
struct foo {
int f_count;
pthread_mutex_t f_lock;
int f_id;
struct foo * f_next;
};
struct foo * foo_alloc (int id )
{
struct foo * fp;
int idx;
if ((fp = (struct foo * ) malloc (sizeof ... | 0 |
#include <pthread.h>
pthread_mutex_t globalMutex[2];
pthread_cond_t globalCondVar[2];
static void *threadFunc1(void *args)
{
assert(args == 0);
pthread_mutex_lock(&globalMutex[0]);
pthread_cond_wait(&globalCondVar[0], &globalMutex[0]);
printf("X modified by threadFunc 1\\n");
pthr... | 1 |
#include <pthread.h>
pthread_mutex_t lock;
int Var = 0;
void *thread_function2(void *arg) {
while (1) {
sleep(1);
pthread_mutex_lock(&lock);
Var++;
pthread_mutex_unlock(&lock);
printf("I am in Thread2 Var = %d\\n", Var);
}
pthrea... | 0 |
#include <pthread.h>
int q[5];
int source[7];
int qsiz;
pthread_mutex_t mq;
void *queue_insert (void * arg)
{
int done = 0;
int i = 0;
int x = 1;
qsiz = 5;
while (done == 0)
{
pthread_mutex_lock (&mq);
if (qsiz < 5)
{
done = 1;
q[qsiz] = x... | 1 |
#include <pthread.h>
struct pthread_args
{
long iterations;
pthread_mutex_t mutex;
};
void *calculate_pi(void *ptr)
{
struct pthread_args *attr = ptr;
double lsum = 0.0;
for(;;)
{
pthread_mutex_lock(&(attr->mutex));
long i = attr->iterations;
attr->iterations = attr->ite... | 0 |
#include <pthread.h>
struct {
int maxproc;
int *pids;
int terminate;
procfunc_t func;
void *param;
pthread_mutex_t mutex;
pthread_cond_t cond;
} PCtrlParam;
static void *_monitor(void *);
static void _sigusr1(int sig);
static void _sigusr1_child_default(int sig);
i... | 1 |
#include <pthread.h>
struct xml_cntn_rcvr *xml_cntn_rcvr_create()
{
struct xml_cntn_rcvr *new = malloc(sizeof(*new));
new->seq = 0;
new->subcllst = 0;
assert(!pthread_cond_init(&new->cond, 0));
assert(!pthread_mutex_init(&new->mutex, 0));
return new;
}
void xml_cntn_rcvr_delete(struct x... | 0 |
#include <pthread.h>
int thread_flag;
pthread_cond_t thread_flag_cv;
pthread_mutex_t thread_flag_mutex;
void wait_n_secs(int seconds, unsigned char show_output)
{
int i;
for (i = 1; i <= seconds; ++i)
{
usleep(1000000);
if (show_output)
printf("Second %d\\n", i);
}
}
v... | 1 |
#include <pthread.h>
int SIZE = 500;
int generations_amount = 500;
int num = 0;
int freq = 100;
pthread_t thread[8];
pthread_t thread_init;
int end[8];
char map[2][8000][8000];
unsigned long long mask = 0;
int was_printed = 0;
int was_initialized = 0;
pthread_mutex_t lock = PTHREAD_MUTEX_INITIA... | 0 |
#include <pthread.h>
{
pthread_mutex_t mutex;
pthread_cond_t cond;
} Lock_pl_t;
void LOCK_PL_init(void **handle)
{
Lock_pl_t *lock = (Lock_pl_t *)malloc(sizeof(Lock_pl_t));
pthread_mutex_init(&lock->mutex, 0);
pthread_cond_init(&lock->cond, 0);
*handle = lock;
return;
}
void LOCK_... | 1 |
#include <pthread.h>
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static const int N = 5;
char warunek = 0;
static void* watek(void* numer){
printf("\\t uruchomiono watek numer: %d\\n",(int)numer);
while(1){
pthr... | 0 |
#include <pthread.h>
int is_prime(uint64_t p)
{ uint64_t premier = 0;
uint64_t i=2;
while (i<p && premier==0)
{ if (p%i==0)
{ premier=1;
}
i++;
}
return premier;
}
void print_prime_factors(uint64_t n)
{ printf("%lu:", n);
uint64_t i=2;
while (i<=n)
{ if (n%i==0)
{ printf(" %lu"... | 1 |
#include <pthread.h>
void *sum(void *p);
unsigned long int psum;
char padding[64 - sizeof(unsigned long int)];
} Psum;
Psum psum[8];
unsigned long int sumtotal = 0;
unsigned long int n;
int numthreads;
pthread_mutex_t mutex;
int main(int argc, char **argv) {
pthread_t tid[8];
int i,... | 0 |
#include <pthread.h>
int DEBUG = 0;
int NUM_THREADS = 5;
int left(int phil_id)
{
return phil_id;
}
int right(int phil_id)
{
if (phil_id == NUM_THREADS - 1)
{
return 0;
}
else return phil_id + 1;
}
static pthread_mutex_t mutexes[5];
void chopsticks_init()
{
... | 1 |
#include <pthread.h>
static int64_t _hdr_phaser_get_epoch(int64_t* field)
{
return __atomic_load_n(field, 5);
}
static void _hdr_phaser_set_epoch(int64_t* field, int64_t val)
{
__atomic_store_n(field, val, 5);
}
static int64_t _hdr_phaser_reset_epoch(int64_t* field, int64_t initia... | 0 |
#include <pthread.h>
struct foo* fh[29];
pthread_mutex_t hashlock = PTHREAD_MUTEX_INITIALIZER;
struct foo {
int f_count;
pthread_mutex_t f_lock;
struct foo* f_next;
int f_id;
};
struct foo* foo_alloc(int id) {
struct foo *fp;
int idx;
if((fp = (struct foo*)malloc(... | 1 |
#include <pthread.h>
pthread_mutex_t mutex;
pthread_cond_t fumatori;
pthread_cond_t nfumatori;
int occupatiS1_nf;
int occupatiS2_f;
int occupatiS2_nf;
int fumatoriAttesa;
int nfumatoriAttesa;
} sala;
sala S;
void nfumatori_entra(sala *s, int *sala)
{
int i;
pthread_mutex_lock(&s... | 0 |
#include <pthread.h>
pthread_mutex_t the_mutex;
pthread_cond_t condc,condp;
int buffer = 0;
void *producer(void *ptr)
{
int i;
for(i = 1; i<=100000000;i++)
{
pthread_mutex_lock(&the_mutex);
while(buffer !=0) pthread_cond_wait(&condp, &the_mutex);
buffer=i;
pthread_cond_signal(&condc)... | 1 |
#include <pthread.h>
pthread_mutex_t m[6];
void *th(void *arg)
{
unsigned id = (unsigned long) arg;
int i = id;
int j = 1;
while (i < 6 && j < 4) {
pthread_mutex_lock(&m[i]);
i+=j;
j++;
}
while (i > id) {
j--;
i-=j;
pthread_mutex_unlock(&m[i]);
}
return 0;
}
int ma... | 0 |
#include <pthread.h>
_dataType data;
struct _node* next;
}node,*nodep,**nodepp;
nodep head = 0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
nodep buyNode(_dataType val)
{
nodep tmp = (nodep)malloc(sizeof(node));
if(tmp!= 0)
{
tmp->da... | 1 |
#include <pthread.h>
long points_per_runner;
long daire_ici;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
struct point {
float x;
float y;
};
long thread_basina_iterasyonu_hesapla(long iterasyon_sayisi, int thread_sayisi) {
return (iterasyon_sayisi / thread_sayisi);
}
int icerid... | 0 |
#include <pthread.h>
void *pth_functionProducer();
void *pth_functionConsumer(void *);
int count=0;
int fp;
pthread_mutex_t Rmutex;
{
off_t offset;
char data[4096];
}NODE;
struct BUF
{
int flag;
NODE *node;
}buf[10];
int isEmpty();
int isFull();
int main(int argc,char *argv[])
... | 1 |
#include <pthread.h>
{
int job;
struct jobnode* next;
}JOB;
JOB *head=0,*tail=0,*new_job,*traverse;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
void *job_checking(void *arg)
{
for(;traverse!=0;)
{
pthread_mutex_lock(&mutex);
printf("Job %d got checked by thread id: %d.\\n",traverse->j... | 0 |
#include <pthread.h>
int g_signaled = 0;
pthread_mutex_t g_lock;
pthread_cond_t g_cond;
void *wait(void *data) {
pthread_mutex_lock(&g_lock);
while (g_signaled == 0) {
printf("%lu wait cond\\n", pthread_self());
pthread_cond_wait(&g_cond, &g_lock);
}
pthread_mutex_unlock(&... | 1 |
#include <pthread.h>
int count_in=0,count_out=0;
int dist_count[2];
pthread_mutex_t tunnel_in = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t tunnel_out = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t dist[2] = {PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER};
int sem[2];
void in_tunnel(int ... | 0 |
#include <pthread.h>
{
unsigned char status;
char data[1024];
}Block_Info;
static int initindicator = 0;
pthread_mutex_t gmutex = PTHREAD_MUTEX_INITIALIZER;
Block_Info memory_block_arr[2];
int init()
{
memset(memory_block_arr, 0, 2*1024);
}
char * mymalloc(size)
{
int lindex;
if(size> 1... | 1 |
#include <pthread.h>
static pthread_key_t g_tid_key;
static pthread_mutex_t g_thread_id_lock = PTHREAD_MUTEX_INITIALIZER;
static uint32_t g_next_tid = 0;
void unique_tid(void)
{
pthread_mutex_lock(&g_thread_id_lock);
if (g_next_tid != 0) {
pthread_mutex_unlock(&g_thread_id_lock);
r... | 0 |
#include <pthread.h>
int g_itemnum;
struct
{
pthread_mutex_t mutex;
int buff[(100000)];
int nindex;
int nvalue;
} shared;
void* producer(void*);
void* consumer(void*);
int main(void)
{
int i;
int threadnum, threadcount[(10)];
pthread_t tid_producer[(10)], tid_consu... | 1 |
#include <pthread.h>
extern struct point p[MAX_POINTS];
extern struct point u[MAX_CENTERS];
extern int c[MAX_POINTS];
extern int iters;
extern struct global_cluster cal_centre;
extern pthread_mutex_t glob_clust_lock;
extern pthread_barrier_t thrd_bar;
void *k_means(void *parameter)
{
int i ... | 0 |
#include <pthread.h>
void *Tackle(void *Dummy) {
extern pthread_cond_t Snap;
extern pthread_mutex_t Mutex;
pthread_mutex_lock(&Mutex);
printf("Waiting for the snap\\n");
pthread_cond_wait(&Snap,&Mutex);
pthread_mutex_unlock(&Mutex);
printf("Tackle!!\\n");
return(... | 1 |
#include <pthread.h>
pthread_mutex_t lock;
pthread_mutex_t lock2;
int value;
int value2;
sem_t sem;
void *functionWithCriticalSection(int* v2) {
pthread_mutex_lock(&(lock));
value = value + *v2;
pthread_mutex_unlock(&(lock));
sem_post(&sem);
}
void *functionWithOtherCriticalSe... | 0 |
#include <pthread.h>
int queue[10 + 1];
int r = 0;
int f = 0;
int over = 0;
pthread_mutex_t m;
pthread_cond_t c;
void enqueue(int n)
{
queue[++r] = n;
}
int dequeue()
{
return queue[++f];
}
int q_empty()
{
return f == r;
}
void* producer(void* p)
{
int n = *(int*)p;
for(int i = 0; i < n; +... | 1 |
#include <pthread.h>
void hello();
void world();
void again();
pthread_mutex_t mutex;
pthread_cond_t done_hello, done_world;
int done = 0;
int main (int argc, char *argv[]){
pthread_t tid_hello,
tid_world, tid_again;
pthread_mutex_init(&mutex, 0);
pthread_cond_init(... | 0 |
#include <pthread.h>
pthread_t t[7];
pthread_mutex_t mtx[10];
int sum_rest[10];
void * doIt(void *arg) {
int i;
for(i = 0; i < 100; ++ i) {
int x = rand() % 10000;
printf("Thread mod: %d, nr: %d\\n", x % 10, x);
pthread_mutex_lock(&mtx[x % 10]);
sum... | 1 |
#include <pthread.h>
pthread_mutex_t mutex;
pthread_cond_t cond_lei;
pthread_cond_t cond_esc;
int escritoras = 0, leitoras = 0, filaEsc = 0;
{
int contador;
int idThread;
} File;
File a;
void init_leitora(){
pthread_mutex_lock(&mutex);
while(escritoras > 0 || filaEsc > 0){
pthre... | 0 |
#include <pthread.h>
struct gamelock
{
void* object;
sem_t readOnly;
sem_t modify;
pthread_mutex_t atom;
};
struct gamelock* gamelock_new(void* object)
{
struct gamelock* lock;
lock = malloc(sizeof(struct gamelock));
if (lock == 0) {
pok_exception_flag_memory_e... | 1 |
#include <pthread.h>
{
int readers;
int slots[10];
}mem_structure;
mem_structure *stocklist;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
sem_t *stop_writers;
int shmid;
pthread_t my_threads[5 + 5];
int id[5 + 5];
void init()
{
sem_unlink("STOP_WRITERS");
stop_writers = sem_o... | 0 |
#include <pthread.h>
pthread_mutex_t theMutex;
pthread_cond_t theCond;
int val;
struct _buffer *next;
} buffer;
buffer *beginBuf;
void* producer(void *args);
void* consumer(void *args);
void insert(int n);
int get();
int getSize(buffer *buf);
int isPrime(long unsigned int n);
void p... | 1 |
#include <pthread.h>
pthread_t thread;
int terminate;
struct NWORKQUEUE *workqueue;
struct NWORKER *prev;
struct NWORKER *next;
} nWorker;
void (*job_function)(struct NJOB *job);
void *user_data;
struct NJOB *prev;
struct NJOB *next;
} nJob;
struct NWORKER *workers;
struct NJOB *waiti... | 0 |
#include <pthread.h>
int main(int argc, char const *argv[])
{
srand(time(0));
int i,tmp[P],err;
err = pthread_mutex_init(&disp_mutex,0);
assert(!err);
for(i = 0;i < P;++i) {
forkState[i] = 1;
phil_cycles[i] = 0;
err = pthread_mutex_init(&mutex[i],0);
assert(!err);
}
for(i = 0;... | 1 |
#include <pthread.h>
enum {
QUEUE_BUF_SIZE = 100000,
};
int size;
int tail;
void **buf;
} vector_t;
int front;
int tail;
int max_size;
void **cyclic_buf;
} queue_cycl_t;
vector_t *vector_init(int size)
{
vector_t *tmp = 0;
tmp = (vector_t *)calloc(1, siz... | 0 |
#include <pthread.h>
const int LAST_CUSTOMER_ARRIVAL_TIME = 59;
int customerCounter = 0;
int (*queue)[10];
int lineFront[10];
pthread_mutex_t queueMutex;
void* customer(void*);
pthread_t* newCustomer(int sellerIndex)
{
pthread_t customerThreadID;
pthread_attr_t custom... | 1 |
#include <pthread.h>
pthread_mutex_t spoon[5];
void phil_init(int a, int* b, int* c)
{
*b=(a>0) ? a-1 : 5;
*c=a;
printf("Philosopher %d started\\n", a+1);
return;
}
int check_If_Spoons_Are_Available(int a, int b, int c)
{
int sum=0;
if(a&1)
{
sum = pthread_mutex_trylock(&spoon[c]... | 0 |
#include <pthread.h>
sem_t forks[5];
pthread_mutex_t mutex;
void init ( )
{
int i;
for ( i = 0 ; i < 5 ; i++ )
sem_init(&forks[i],0,1);
}
void * philosopher ( void* arg )
{
int* p = (int*)arg;
int x = *p;
while ( 1 )
{
pthread_mutex_lock(&mutex);
... | 1 |
#include <pthread.h>
struct pp_thread_info {
int *msgcount;
pthread_mutex_t *mutex;
pthread_cond_t *wait_cv;
pthread_cond_t *signal_cv;
char *msg;
int modval;
};
void *
pp_thread(void *arg)
{
struct pp_thread_info *infop;
int c;
infop = arg;
wh... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.