text
stringlengths
192
6.24k
label
int64
0
1
#include <pthread.h> int threadCount, bufSize, itemsPerProducer; static int index = 0; int* buf; sem_t empty; sem_t full; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; void* producer(void* id); void* consumer(void* id); struct threadAttr { int id; }; int main(int argc, char** argv...
1
#include <pthread.h> char * buf; int buf_size; int *num_open; pthread_mutex_t *lock; pthread_cond_t *other; pthread_cond_t *self; } arg_t; void * producer_thread(void * arg) { int pos = 0; arg_t * args = (arg_t *)arg; const char *str = "Product.\\n"; size_t ...
0
#include <pthread.h> void *Producer(void *); void *Consumer(void *); sem_t empty; sem_t full; pthread_mutex_t mutex; int g_data[20]; int N; int main(int args, char* argv[]) { N = atoi(argv[1]); int id[N]; pthread_t pid[N], cid[N]; sem_init(&empty, 1, 20); sem_init(&full, 1, 0)...
1
#include <pthread.h> sem_t tray_full_sem; pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t tray_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t student_wait_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t student_total_lock = PTHREAD_MUTEX_INITIALIZER; pthre...
0
#include <pthread.h> struct foo { int f_count; pthread_mutex_t f_lock; }; struct foo *fp; struct foo * foo_alloc(void) { struct foo *fp; if ((fp = malloc(sizeof(struct foo))) != 0) { fp->f_count = 1; if (pthread_mutex_init(&fp->f_lock, 0) != 0) { ...
1
#include <pthread.h> pthread_mutex_t mutex; sem_t sem; struct node *head = 0; int create_sockfd(); void * pthread_fun( void *arg); void create_threads(); void send_file(int c, char *s); void recvf_ile(int c,char *s); void sig_fun(int sig) { printf("sig = %d\\n ",sig); } int main() { signa...
0
#include <pthread.h> void * handle_clnt(void * arg); void send_msg(char * msg, int len); void error_handling(char * msg); int clnt_cnt=0; int clnt_socks[2]; char clnt_name[20]= {0}; char clnt_names[2][20]= {0}; pthread_mutex_t mutx; int main(int argc, char *argv[]) { int serv_sock, clnt_s...
1
#include <pthread.h> unsigned int randr(int min, int max); void *random_thread_function(void *arg); void *sort_thread_function(void *arg); void *merge_thread_function(void *arg); int compare (const void * a, const void * b); int number_of_nums; int number_of_threads; int n_thread_sort; long long ...
0
#include <pthread.h> sigset_t new_set, old_set; int lock_USR1; int error_USR2; int stp_stop; pthread_mutex_t mux[5], mux_files; char mystrings[10][10] = { "aaaaaaaaa\\n", "bbbbbbbbb\\n", "ccccccccc\\n", "ddddddddd\\n", "eeeeeeeee\\n", "fffffffff\\n", "ggggggggg\\n", ...
1
#include <pthread.h> int source[15]; int minBound[4]; int maxBound[4]; int channel[4]; int th_id = 0; pthread_mutex_t mid; pthread_mutex_t ms[4]; void sort (int x, int y) { int aux = 0; for (int i = x; i < y; i++) { for (int j = i; j < y; j++) { if (source[i] > source[...
0
#include <pthread.h> { int bUsed; int conf_fd ; struct sockaddr_un conf_addr ; char conf_buf[(16384)]; pthread_mutex_t atomic; char CONF_LOCAL_NAME[16]; char CONF_LISTEN_NAME[16]; int nTimeout; }LocalSockInfo_S,*LPLocalSockInfo; static LocalSockInfo_S s_lo...
1
#include <pthread.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int counter, end; } Shared; Shared *make_shared(int end) { Shared *shared = (Shared *)malloc(sizeof(Shared)); shared->counter = 0; shared->end = end; return shared; } void desalloc_shared(Shared *shar...
0
#include <pthread.h> struct map_2mb { uint64_t pfn_2mb; }; struct map_1gb { struct map_2mb map[1ULL << (30 - 21 + 1)]; }; struct map_128tb { struct map_1gb *map[1ULL << (47 - 30 + 1)]; }; static struct map_128tb vtophys_map_128tb = {}; static pthread_mutex_t vtophys_mutex = PTHREAD_MU...
1
#include <pthread.h> pthread_mutex_t mux = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int i = 0; void * thread_func1(void *arg) { while(i < 9) { pthread_mutex_lock(&mux); if(i % 3 != 0) { pthread_cond_wait(&cond, &mux); ...
0
#include <pthread.h> void *writer(void*); void *reader(void*); int sharedValue = 0; int readCount = 0; int writeCount = 0; pthread_mutex_t dbMutex, readMutex; int main(int argc, char *argv[]) { int numReaders; int numWriters; int i; if (argc == 3) { numReaders = atoi(a...
1
#include <pthread.h> int sigpending (sigset_t *set) { struct signal_state *ss = &_pthread_self ()->ss; pthread_mutex_lock (&ss->lock); *set = (ss->pending | process_pending) & ss->blocked; pthread_mutex_unlock (&ss->lock); return 0; }
0
#include <pthread.h> static pthread_key_t key; static pthread_once_t init_done = PTHREAD_ONCE_INIT; pthread_mutex_t env_mutex = PTHREAD_MUTEX_INITIALIZER; extern char **environ; static void thread_init(void) { pthread_key_create(&key, free); } char * getenv(const char *name) { int i; in...
1
#include <pthread.h> int thread_count; int local_n; double a, b, h, n, local_a, local_b; double local_int; double total_int = 0; pthread_mutex_t mutex; sem_t sem; void Usage(char* prog_name); void Read_data(double* a, double* b, double* n); void *Pth_trap(void* rank); double Trap(double left_endp...
0
#include <pthread.h> int number=0; void* add(void *ii) { int *num=(int*)ii; int count=10000; while(--count) { (*num)++; } return 0; } void* addlk(void *arg) { pthread_mutex_t *plock = (pthread_mutex_t*)arg; int cnt=10000; while(--cnt) { ...
1
#include <pthread.h> const char *REF_FILE = "./shm_sem_ref.dat"; int shmid_for_cleanup = 0; pthread_mutex_t *mutex_for_cleanup = 0; struct data { pthread_mutex_t mutex; }; const int SIZE = sizeof(struct data); int create_shm(key_t key, const char *txt, const char *etxt, int flags) { ...
0
#include <pthread.h> struct operation { pthread_cond_t condition; unsigned status; }; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static struct vector operations; bool operations_init(void) { return vector_init(&operations, VECTOR_SIZE_BASE); } void operations_term(void) { ...
1
#include <pthread.h> pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t odd_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER; int countIsOdd = 0; int count = 0; void* oddCounter(void* arg) { int thread_should_exit = 0; int...
0
#include <pthread.h> int broj_sobova = 0, broj_patuljaka = 0; int sob_id[ 11 ], patuljak_id[ 1024 ]; pthread_cond_t u_patuljak[ 1024 ], u_sob[ 11 ], djed; pthread_mutex_t kljuc; pthread_t dretve[ 1024 ]; int dretve_size; void clean_exit( int sig ){ exit( 0 ); } void ulaz_M( pthread_cond_t *uvje...
1
#include <pthread.h> static pthread_key_t key; pthread_mutex_t env_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_once_t init_done = PTHREAD_ONCE_INIT; extern char **environ; static void thread_init(void) { pthread_key_create(&key, free); } char *getenv_r(const char *name, char *buf, ...
0
#include <pthread.h> int inc; int nbthreads; int ok; pthread_t *tid; pthread_mutex_t mutex_inc = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mut_createok = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond_createok = PTHREAD_COND_INITIALIZER; pthread_mutex_t mut_sigint = PTHREAD_MUTEX_INITIALI...
1
#include <pthread.h> int buffer[5]; int bufferindicator = 0; pthread_mutex_t cmutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condvar = PTHREAD_COND_INITIALIZER; void* writer_thread(void *arg) { int loopindex = 0; int bufferindex = 0; pthread_mutex_lock(&cmutex); while(buf...
0
#include <pthread.h> pthread_mutex_t pi_mutex; double iterations; double x,y,z; int count=0; struct timeval tm1, tm2; void start() { gettimeofday(&tm1, 0); } void stop() { gettimeofday(&tm2, 0); unsigned long long t = ((tm2.tv_sec - tm1.tv_sec) * 1000000) + ...
1
#include <pthread.h> pthread_mutex_t lock; void *searchString(void* nama); int main(){ char nama1[100],nama2[100]; scanf("%s",nama1); scanf("%s",nama2); pthread_t t1,t2; pthread_create(&t1,0,searchString,nama1); pthread_create(&t2,0,searchString,nama2); pthread_join(t1,0); pt...
0
#include <pthread.h> int ticket_cnt = 30; { int thd_id_; pthread_mutex_t *p_mutex_; }DATA, *pDATA; void *handler(void *arg) { int thd_id = ((pDATA)arg)->thd_id_; pthread_mutex_t *p_mutex = ((pDATA)arg)->p_mutex_; printf("window %d on! \\n", thd_id); while(1) ...
1
#include <pthread.h> pthread_t wid[2], rid[5]; struct buffer_item{ int rand; int line_number; }; FILE* buffer; int total_line = 0; int readerCnt =0, writerCnt = 0; pthread_mutex_t accessReaderCnt = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t accessWriterCnt = PTHREAD_MUTEX_INITIALIZER; pthrea...
0
#include <pthread.h> static int print_flag = 0; int thread_num; int items_per_thread; int buf[32][10]; int in[32]; int out[32]; int no_elems[32]; int no_items_sent[32]; int no_items_received[32]; pthread_mutex_t lock[32]; pthread_cond_t cond_full[32]; } buffer_t; static buffer_t ...
1
#include <pthread.h> sem_t emptyPot; sem_t fullPot; void *savage (void*); void *cook (void*); static pthread_mutex_t print_mutex; static int servings = 15; int getServingsFromPot(int savage_id) { if (servings > 0) { servings--; printf("-------serving%d------\\n",se...
0
#include <pthread.h> int file_fd; int philNum; char** phils; pthread_mutex_t* forks; pthread_mutex_t screen = PTHREAD_MUTEX_INITIALIZER; double* waitingTime; void PrintLogString(char* s, int id) { time_t timer; char logString[70] = {0}; pthread_mutex_lock(&screen); time(&timer); memcpy(lo...
1
#include <pthread.h> pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t condition_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER; void *functionCount1(); void *functionCount2(); int count = 0; main() { pthread_t threa...
0
#include <pthread.h> void ports_enable_class (struct port_class *class) { pthread_mutex_lock (&_ports_lock); class->flags &= ~PORT_CLASS_NO_ALLOC; if (class->flags & PORT_CLASS_ALLOC_WAIT) { class->flags &= ~PORT_CLASS_ALLOC_WAIT; pthread_cond_broadcast (&_ports_block); }...
1
#include <pthread.h> static void print_newest_message(struct arguments* args); void* writeserver_thread_func(void* arg) { struct arguments* args = arg; struct return_info return_codes; (users+args->user_id)->write_connected = 1; while(1) { print_newest_message(args); sleep(1); return...
0
#include <pthread.h> { pthread_mutex_t *right; pthread_mutex_t *left; pthread_t thread; int num; int fail; int numTimesToEat; } Philosopher; void *simulation(void *p) { Philosopher *phil = (Philosopher*)p; int failed; int tries_left; pthread_mutex_...
1
#include <pthread.h> pthread_mutex_t bankSem; int num_customers; int balance; int id; int type; int amount; }cust_struct; void deposit(int i,int amt); void withdraw(int i,int amt); void cust(cust_struct * info); int main(int argc,char *argv[]){ int n,type; cust_struct *info; pt...
0
#include <pthread.h> pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER; void prepare(void) { printf("preparing locks...\\n"); pthread_mutex_lock(&lock1); pthread_mutex_lock(&lock2); } void parent(void) { printf("parent unlocking ...
1
#include <pthread.h> struct pp_thread_info { int *msgcount; pthread_mutex_t *mutex; char *msg; int modval; }; void * pp_thread(void *arg) { int c, done; struct pp_thread_info *infop; infop = arg; done = 0; while (1) { pthread_mutex_lock(inf...
0
#include <pthread.h> int threads=1024; int threads_max=20; int counter1=0; int counter1_start=180000; int counter1_stop=1000000; int counter1_warn=200000; int counter_de_nr=0; int koniec=0; int sleep_time=750; int *ile_watk; pthread_cond_t warunek1 = PTHREAD_COND_INITIALIZER; pthread_mutex_...
1
#include <pthread.h> struct ks_xact *ks_xact_alloc(struct ks_conn *conn) { struct ks_xact *xact; xact = malloc(sizeof(*xact)); if (!xact) return 0; memset(xact, 0, sizeof(*xact)); xact->refcnt = 1; xact->conn = conn; xact->id = conn->seqnum; xact->autocommit = TRUE; xact->state...
0
#include <pthread.h> static int hash(int key) { return key % MAGICNO; } void htable_init(struct hashtable **ht, void (*value_free)(void *value)) { *ht = malloc(sizeof(struct hashtable)); assert(*ht); (*ht)->htable = malloc(sizeof(struct hashnode *) * HTSIZE); assert((*ht)->...
1
#include <pthread.h> pthread_mutex_t mutexa, mutexb; void *fun() { int i = 1000; while(i--) { pthread_mutex_lock(&mutexa); printf("-\\n"); pthread_mutex_unlock(&mutexb); } } int main(int argc, char* argv[]) { int i = 1000; pthread_t pthid; ...
0
#include <pthread.h> int test1; int test2; pthread_mutex_t lock; pthread_cond_t can_cond; pthread_cond_t I_cond; void *printHello(void *args){ pthread_mutex_lock(&lock); flockfile(stdout); fprintf(stdout, "Never going to give you up\\n"); funlockfile(stdout); pthread_cond_signal(&can_cond);...
1
#include <pthread.h> int thread_count; int flag = 0; long long n; double sum = 0; pthread_mutex_t mutex; void* Thread_sum(void* rank){ long my_rank = (long) rank; double factor, my_sum = 0.0; long long i; long long my_n = n/thread_count; long long my_first_i = my_n * my_rank; ...
0
#include <pthread.h> { int balance; pthread_mutex_t mutex; } Account; void deposit(Account* account, int amount) { pthread_mutex_lock(&(account->mutex)); account->balance += amount; pthread_mutex_unlock(&(account->mutex)); } Account account; void *thread_start() { int i; ...
1
#include <pthread.h> int dlugosc(int x){ int l=0; while(x!=0){ x/=10; l++; } return l; } char* slowo; int ilosc_rekordow; int fd; pthread_t *tablica_watkow; int ilosc_watkow; sigset_t set; }parametry; pthread_mutex_t mutex; pthread_t main_t...
0
#include <pthread.h> void fun(void); pthread_mutex_t mut= PTHREAD_MUTEX_INITIALIZER; void *thread_func(void *args) { if(pthread_mutex_trylock(&mut) == EBUSY) { printf("%lu: Mutex already Locked\\n",pthread_self()); } else { printf("Mutex was free.. So I (%lu) Taken \\n",pthread_self());...
1
#include <pthread.h> struct Node{ int value; struct Node *next; }*head; pthread_mutex_t inserter_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t deleter_lock = PTHREAD_MUTEX_INITIALIZER; sem_t deleter_lock_searcher; sem_t deleter_lock_inserter; void searcher(); void inserter(); void ...
0
#include <pthread.h> int g1, g2, g3, g4; int found = 1; float goertzel(int N,int Ft, float* input) { int k, i; float floatN; float omega, sine, cosine, q0, q1, q2, power; float scalingFactor = N / 2.0; floatN = (float) N; k = (int) (0.5 + ((floatN * Ft) / Fs)); omeg...
1
#include <pthread.h> int count = 0; int thread_ids[3] = {0,1,2}; pthread_mutex_t count_mutex; pthread_cond_t count_threshold_cv; void *watch_count(void *t); void *inc_count(void *t) ; int main (int argc, char *argv[]) { int i, rc; long t1=1, t2=2, t3=3; pthread_t threads[3]; pthrea...
0
#include <pthread.h> static const size_t NUM_ITERATIONS = 100; static const size_t NUM_THREADS = 4; { pthread_mutex_t lock; size_t value; } counter_t; counter_t* counter_init(size_t initial_value) { counter_t* counter = (counter_t*)malloc(sizeof(counter_t)); counter->value = init...
1
#include <pthread.h> static volatile int keepRunning = 1; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_barrier_t mybarrier; static unsigned int maxIteration = 0; void intHandler(int _) { keepRunning = 0; } struct job { unsigned int threadNumber; unsigned ...
0
#include <pthread.h> pthread_cond_t var_cond ; pthread_mutex_t mutex_cond; pthread_mutex_t sem; int worms = 7; int scream = 0 ; struct DATA { int num ; char name[10]; } ; void *parent(void *dad){ struct DATA *aa = (struct DATA *)dad ; while(1){ pthread_mutex_lock(...
1
#include <pthread.h> void* producer(void*); void* consumer(void*); sem_t full_sem, empty_sem; pthread_mutex_t buffer_mutex; int buffer[10], buffer_index=0; main(){ pthread_t tid[10]; int thread[10]; sem_init(&full_sem, 0, 5); sem_init(&empty_sem, 0, 0); pthread_mutex_init(&buffer_mutex...
0
#include <pthread.h> sem_t barber,customer; pthread_mutex_t mutex; int waiting=0; int count=0; void* barber1(void* param){ while(1){ sem_wait(&customer); pthread_mutex_lock(&mutex); waiting=waiting-1; printf("Cut Hair \\n"); sem_post(&barber); pthread_mutex_unlock(&mutex); count++; if(...
1
#include <pthread.h> void* LockCreate() { pthread_mutexattr_t attr; pthread_mutex_t *p_mutex = malloc(sizeof(pthread_mutex_t)); int i_result; pthread_mutexattr_init( &attr ); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); i_result = pthread_mutex_init( p_mutex, &attr ); ...
0
#include <pthread.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static void *threads(void* arg) { (void)arg; printf("\\t->Thread %ld wartet auf Bedingung\\n", (long)pthread_self()); pthread_mutex_lock(&mutex); pthread_cond_wait(&con...
1
#include <pthread.h> pthread_mutex_t mut[5]; int workreq[5]; int workdone[5]; pthread_mutex_t prodmut; unsigned prodbuff; void *worker (void *arg) { unsigned id = (unsigned long) arg; int i, havework; havework = 0; for (i = 0; i < 2; i++) { pthread_mutex_lock (mut + id); ...
0
#include <pthread.h> struct validlink { char src[40]; char dst[40]; char filename[20]; int startposition; int endposition; }; int alllink=0; struct validlink link[100]; pthread_mutex_t mut; void exchange(int arg1) { int arg = arg1; FILE* fp1; FILE* fp2; fp1 = fopen("remoteinformation", "w"); fp2 ...
1
#include <pthread.h> struct reg { int *inicio; int *fim; int *vet; int n; }; int somatorio; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void * function (void *arg) { struct reg *valor; valor = (struct reg*) arg; printf("inicio ...
0
#include <pthread.h> int **weights; char *string1,*string2; int N, M; pthread_mutex_t **locks; struct thread_params{ int id; int s_index; int l_index; int col_height; }; int max_threads; struct thread_params *thread_info; void *initialize_locks(void *thread_info); void *compute_weights(void *...
1
#include <pthread.h> double gettime(void) { struct timeval tv; gettimeofday(&tv, 0); return tv.tv_sec + tv.tv_usec * 1e-6; } int val; struct _tnode *l; struct _tnode *r; } tnode; tnode *btree_create() { return 0; } tnode *btree_insert(int v, tnode *t) { if (t == 0) { t = (tnode *)...
0
#include <pthread.h> char task[] = "abcdefg"; char buffer1[4]; char buffer2[4]; int in; int out; int buffer_is_empty(){ return in == out; } int buffer_is_full(){ return (in + 1)%4 == out; } char get_item(){ int item; item = buffer1[out]; out = (out + 1)%4; return item; } void chan...
1
#include <pthread.h> char knockCount; char idCount; pthread_mutex_t gateLock; pthread_mutex_t idLock; pthread_mutex_t* threadLock; pthread_t gateThread; void trySort() { pthread_mutex_lock(&gateLock); knockCount++; printf("Knocked %d time(s)\\n", knockCount); pthread_mutex_unlock(&gat...
0
#include <pthread.h> int count = 0; pthread_mutex_t count_mutex; pthread_cond_t count_threshold_cv; void *inc_count(void *t) { int i; long my_id = (long)t; for (i=0; i < 10; i++) { pthread_mutex_lock(&count_mutex); count++; if (count == 12) { ...
1
#include <pthread.h> double pi_final; pthread_mutex_t m; int compute_pi(int interval, int N) { int i; double pi, step, x, sum=0.0; step = 1/(double)(long int) 1000000000; for(i=((long int) 1000000000/N)*interval; i<((long int) 1000000000/N)*(interval+1); i++) { x = (i+0.5)*step; su...
0
#include <pthread.h> struct send_package_queue *InitQueue(void) { struct send_package_queue *pqueue = (struct send_package_queue *)malloc(sizeof(struct send_package_queue)); if(pqueue!=0) { pqueue->front = 0; pqueue->rear = 0; pqueue->size = 0; pthread_mu...
1
#include <pthread.h> struct uart_send_buf rs232_send_list[SEND_BUFF_SIZE + 1]; unsigned char rs232_read_current = 0, rs232_write_current = 0; void msg_write_to_list(unsigned char *date,unsigned char len) { unsigned char parket_len = rs232_send_list[rs232_write_current].datelen; pthread_mutex...
0
#include <pthread.h> { unsigned long long id; unsigned char data[1024]; } Package; int fd_audio; int isbusy_audio; pthread_mutex_t mutex_isbusy_audio,mutex_isbusy_audio; unsigned long long current_recv_id,current_send_id; pthread_mutex_t mutex_local_recv,mutex_local_send,lock_...
1
#include <pthread.h> int check_primes(int a, int b); int start; int end; int sum; int tid; int stolen; int jobs; }* prime_arg_t; pthread_mutex_t m; void* prime_th(void* _arg) { prime_arg_t arg = _arg; arg->sum = check_primes(arg->start, arg->end); return 0; } void* d...
0
#include <pthread.h> int threads, n, range,tasks,linked_list_size=0,task_count; pthread_mutex_t mutex; pthread_rwlock_t rwlock; struct linked_list { int data; struct linked_list *next; }; struct linked_list *head,*tail,*new,*temp; void insert(int value) { if (tail == 0) { ...
1
#include <pthread.h> pthread_mutex_t mutexsum; int *a, *b; long sum=0.0; void *dotprod(void *arg) { int i, start, end, offset, len; long tid; tid = (long)arg; offset = tid; len = 4; start = offset*len; end = start + len; printf("thread: %ld starting. start...
0
#include <pthread.h> pthread_mutex_t count_mutex; pthread_mutex_t condition_mutex; pthread_cond_t condition_cond; void *functionCount1(); void *functionCount2(); int count = 0; main() { pthread_mutex_init(&count_mutex, 0); pthread_mutex_init(&condition_mutex, 0); pthread_cond_init(&conditi...
1
#include <pthread.h> struct synch_linked_list * synchronous_linked_list(void (*print)(void *), void (*destructor)(void *)){ struct synch_linked_list * list = ALLOC(*list, 1); list->mutex = ALLOC(*list->mutex, 1); pthread_mutex_init(list->mutex, 0); list->head = 0; list->tail = 0; ...
0
#include <pthread.h>extern void __VERIFIER_error() ; unsigned int __VERIFIER_nondet_uint(); static int top=0; static unsigned int arr[(400)]; pthread_mutex_t m; _Bool flag=(0); void error(void) { ERROR: __VERIFIER_error(); return; } void inc_top(void) { top++; } void dec_...
1
#include <pthread.h> struct signal { int active; pthread_mutex_t mutex; pthread_cond_t condition; }; static struct signal sig = { .active = 0, .mutex = PTHREAD_MUTEX_INITIALIZER, .condition = PTHREAD_COND_INITIALIZER }; void* signal_thread (void* param) { sleep(...
0
#include <pthread.h> static pthread_mutex_t mutex; int dao_queue_init(struct DaoQueueFlag *queueFlag, int queueNum, struct DaoQueue **queues, struct DaoQueueDate **queueDates) { pthread_mutex_init(&mutex, 0); if(queueNum==0) { return DAOFAILURE; } int i; fo...
1
#include <pthread.h> int element[(20)]; int head; int tail; int amount; } QType; pthread_mutex_t m; int nondet_int(); int stored_elements[(20)]; _Bool enqueue_flag, dequeue_flag; QType queue; int init(QType *q) { q->head=0; q->tail=0; q->amount=0; } int empty(QType *...
0
#include <pthread.h> int value; int status; enum { ON, OFF, }; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; void *thread_one(void *arg) { pthread_mutex_lock(&mutex); value = 5; status = OFF; pthread_cond_signal(&cond); printf("%d\\...
1
#include <pthread.h> int buffer[1024]; int count=0; pthread_mutex_t mutex1; pthread_mutex_t mutex2; void *threadFun1(void *arg) { int i; while(1) { pthread_mutex_lock(&mutex1); printf("Thread 1\\n"); count++; pthread_mutex_unlock(&mutex2); } } void *threadFun2(void *arg) { int ...
0
#include <pthread.h> volatile int servings = 0; volatile int savagesNumber = 0; volatile int maxServings = 0; sem_t emptyPot; sem_t fullPot; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void getInput(){ clear(); move(0, 0); printw("Digite o numero maximo de pratos: "); refresh(); ...
1
#include <pthread.h> struct server { int nr_threads; int max_requests; int max_cache_size; int *buffer; }; void fill_in(struct server *sv, int connfd); int process(struct server *sv); void worker_function (struct server *sv); int in=0; int out=0; pthread_mutex_t lock = PTHREAD_MUTEX_I...
0
#include <pthread.h> static int keep_ticks; static void *tickTurn(void *ptr); static struct turn_info turnInfo; static struct listenConfig listenConfig; static pthread_t turnListenThread; static pthread_t turnTickThread; static char permission_ip[1000]; static char message[100]; static char ...
1
#include <pthread.h> void *assistantThread(); void *studentThread(); pthread_mutex_t assistantMutex; pthread_mutex_t studentMutex; int main() { pthread_t assistantID; srand(time(0)); pthread_mutex_t assistantMutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t studentMutex = PTHREAD_MUTEX_INI...
0
#include <pthread.h> pthread_mutex_t mutex[5]; void chopsticks_init(){ int i; for (i = 0; i < 5; i++){ assert(!pthread_mutex_init(&mutex[i],0)); } } void chopsticks_destroy(){ int i; for (i = 0; i < 5; i++){ assert(!pthread_mutex_destroy(&(mutex[i]))); } } void pickup_cho...
1
#include <pthread.h> void send(int); int receiveAndSync(int, int); void * worker(); int N_THREADS = 0; int N_LIMIT = 0; int BUFFER = 0; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int main(int argc, char* argv[]) { if (argc < 2) {...
0
#include <pthread.h> static int filename_parse(char * filename, struct dir_instance_t * elem) { int i = 0; int tokens = 0; char * str = filename; char prefix[8] = ""; char block_id[64] = ""; char ip_str[64] = ""; char * curr_str = prefix; while (*str){ if (*str == '+'){ tokens++; ...
1
#include <pthread.h> struct queueNode { int key; struct queueNode *next; }; struct queueHeader { struct queueNode *head; struct queueNode *tail; }; void *hwthread(void *arg); void enqueue(struct queueHeader *qh, int key); int* dequeue(struct queueHeader *qh); int isEmpty(struct queueHeade...
0
#include <pthread.h> int stoj = 0, slachticiCount = 0, poddaniCount = 0; int cakajuciSlachtici = 0, slachticiVnutri = 0, poddaniVnutri = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condPoddani = PTHREAD_COND_INITIALIZER; pthread_cond_t condSlachtici = PTHREAD_COND_INI...
1
#include <pthread.h> int G_CHUNK_SIZE; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; large_uint G_current_start; large_uint G_subset_count; int G_terminated_flag; large_uint G_steps; void increment_step() { pthread_mutex_lock(&mutex); G_steps++; pthread_mutex_unlock(&mutex); } struct s...
0
#include <pthread.h> int thread_count; int message; int consumeOK; void *Consumer(void* rank); void *Producer(); int count; pthread_mutex_t mutex; pthread_cond_t cv; int r; int main(int argc, char* argv[]){ long thread; pthread_t idp; pthread_t* thread_handles; srand(time(0)); int i ...
1
#include <pthread.h> struct RwLock { int nreaders; pthread_mutex_t rw_mutex; pthread_cond_t rw_cond; }; void initRwLock(struct RwLock *rwp) { rwp->nreaders = 0; pthread_mutex_init(&rwp->rw_mutex, 0); pthread_cond_init(&rwp->rw_cond, 0); } void getReadLock(struct RwLo...
0
#include <pthread.h> int BUFFER_SIZE = 10; int THREAD_COUNT = 6; int NUM_PRODUCERS = 2; int NUM_CONSUMERS = 2; int MAX_ITEMS = 20; int * buffer; int buffer_index; pthread_mutex_t buffer_mutex; sem_t full_semaphore; sem_t empty_semaphore; void buffer_insert(int num){ if(buffer_in...
1
#include <pthread.h> static struct { int flags; int state; struct { int flag; int sock; int time; } items[8]; pthread_t thrd; pthread_mutex_t lock; } _nexusio_mftp_watch_dog_zone; void * _nexusio_mftp_watch_dog_thrd_func(void *argp) { int f; int i; void *p ; p = argp; ...
0
#include <pthread.h> unsigned long totalhits; pthread_mutex_t hits_lock; void *calc_hits(int *mynum) { unsigned long localhits=0,myiter; int i; double dx, dy; short state[3]; long myseed; struct timeval now; gettimeofday(&now, 0); ...
1
#include <pthread.h> const int NUM_THREADS = 100; pthread_mutex_t mutex; { int *count; } arg_struct; void *countThread(void *arg) { int *count = ((arg_struct *) arg)->count; int i; for(i=0; i<1000; i++) { pthread_mutex_lock(&mutex); (*count)++; pthread_mutex_unlock(&mutex); } Pthrea...
0
#include <pthread.h> pthread_t tids[10]; int cherries[10]; int all_cherries; pthread_mutex_t mutex; void *ThreadAdd(void * a) { int index = (int)a; int i,j,y; y = 0; for(i = 0; i < 100000; i++) { cherries[index]++; while (pthread_mutex_trylock(&mutex) != 0) { ...
1
#include <pthread.h> uint32_t id; uint32_t op; uint8_t *data; uint32_t leng; struct _qentry *next; } qentry; qentry *head,**tail; void *semfree,*semfull; pthread_mutex_t lock; } queue; void* queue_new(uint32_t size) { queue *q; q = (queue*)malloc(sizeof(queue)); q->head = 0; q->tai...
0