text
stringlengths
192
6.24k
label
int64
0
1
#include <pthread.h> unsigned long max; int num_threads; unsigned long factor = 1; unsigned char *bitmap = 0; pthread_mutex_t mutex_bitmap = PTHREAD_MUTEX_INITIALIZER; void *isPrime(void *arg); int main(int argc, char *argv[]) { int i; num_threads = 50; max = 200000; pt...
1
#include <pthread.h> pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER; void prepare() { printf("prepareing locks..\\n"); pthread_mutex_lock(&lock1); pthread_mutex_lock(&lock2); } void parent() { printf("parent unlocking..\\n"); pthread_mut...
0
#include <pthread.h> const int NUM_THREADS = 4; const int N = 1000; const int CHUNK_SIZE = N/NUM_THREADS; static double x[N]; static double y[N]; static double z[N]; pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER; double sum = 0.0; void *add(void *threadid) { long tid; tid = (long)thr...
1
#include <pthread.h> int buffer[10]; int current_position = 0; int total_generated = 0; pthread_mutex_t buffer_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t go_calculate = PTHREAD_COND_INITIALIZER; pthread_cond_t go_generate = PTHREAD_COND_INITIALIZER; void printArray(int buffer[]) { int i; ...
0
#include <pthread.h> pthread_t hilosEncolar[10]; pthread_t hilosDesencolar[10]; int final; pthread_cond_t llena, vacia; pthread_mutex_t mutex; int contenido[100]; } cola_t; int numeroAleatorio(){ return rand() % 10; } void crearCola(cola_t *cola){ cola->final = -1; p...
1
#include <pthread.h> int g_Flag=0; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; void* thread1(void*); void* thread2(void*); int main(int argc, char** argv) { printf("enter main\\n"); pthread_t tid1, tid2; int ...
0
#include <pthread.h> double gPi = 0.0; pthread_mutex_t gLock; void *Area(void *pArg) { int myNum = *((int *)pArg); double h = 2.0 / 10000000; double partialSum = 0.0, x; int i; for (i = myNum; i < 10000000; i += 4) { x = -1 + (i + 0.5f) * h; partialSum += sqrt(1.0 - x*x) * h; }...
1
#include <pthread.h> static struct event_base *my_base=0; static pthread_t progress_thread; static bool progress_thread_stop=0; static int progress_thread_pipe[2]; static pthread_mutex_t lock; static struct event write_event; static int my_fd; static bool fd_written=0; static void* progress_e...
0
#include <pthread.h> float arrFrom[1024 * 1024]; float arrTo[1024 * 1024]; float* ptrFrom; float* ptrTo; int steadyState, iterCount, cells50, numThreads; pthread_barrier_t barrier_first; pthread_barrier_t barrier_second; pthread_mutex_t critical_count; pthread_mutex_t critical_steady; doubl...
1
#include <pthread.h> int numOfPassengersOnBus; int flag; void* print_message(void* ptr); pthread_cond_t condFull, condAvailable; pthread_mutex_t lock; int main(int argc, char* argv[]) { pthread_cond_init(&condFull, 0); pthread_cond_init(&condAvailable, 0); pthread_mutex_init(&lock, 0); ...
0
#include <pthread.h> struct prodcons { char buf[16]; pthread_mutex_t lock; int readpos, writepos; pthread_cond_t notempty; pthread_cond_t notfull; }; struct prodcons buffer; void init(struct prodcons * b) { pthread_mutex_init(&b->lock,0); pthread_cond_init(&b->notem...
1
#include <pthread.h> int array[2048*2]; int N=0; { int left; int right; }parameters; parameters *para[2048]; int arraySize=0; pthread_cond_t cv; pthread_mutex_t lock; void readArray(char *fileName){ FILE *fp; int i=0; fp=fopen(fileName,"r"); if(!fp){ printf("ERROR: Cannot read file %s \\...
0
#include <pthread.h> pthread_mutex_t lineMutex; int lineCount=0; char strContain(char*childstr,char*str); char strContainDEFINE(char*str); int countDefine(char*fileName); int find(char * dirName); struct task * next; char* dir; }task; int num; int shutdown; pthread_t* workThread; task* taskH...
1
#include <pthread.h> pthread_t thread1; pthread_mutex_t lock1; void *workOne(void *arg) { pthread_mutex_lock(&lock1); usleep(100); pthread_mutex_lock(&lock1); pthread_mutex_unlock(&lock1); return arg; } int main() { int ret; ret = pthread_mutex_init(&lock1, 0); ...
0
#include <pthread.h> pthread_mutex_t mutex; int scholarship = 4000, total = 0; void *A(void); void *B(void); void *C(void); void *totalCalc(void); int main(void){ pthread_t tid1, tid2, tid3; pthread_create(&tid1, 0, (void *(*)(voi...
1
#include <pthread.h> void * handle_clnt(void * arg); void send_msg(char * msg, int len); void error_handling(char * msg); void color(); void printColorString(int color,char *str); int clnt_cnt=0; int clnt_socks[256]; pthread_mutex_t mutx; char addr_arry[256][20]; int colorS=41; int main(int a...
0
#include <pthread.h> int quitflag; sigset_t mask; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t waitloc = PTHREAD_COND_INITIALIZER; void * thr_fn (void * arg); int main (int argc, char * argv[]) { int err; sigset_t oldmask; pthread_t thread; sigemptyset ...
1
#include <pthread.h> int global_value = 0; pthread_mutex_t global_value_mutex = PTHREAD_MUTEX_INITIALIZER; void *t1_main(void *arg); void *t2_main(void *arg); int main(int argc, char **argv) { pthread_t t1, t2; int code; code = pthread_create(&t1, 0, t1_main, 0); if (code != 0...
0
#include <pthread.h> pthread_mutex_t counter_lock; pthread_cond_t counter_nonzero; int counter = 0; int estatus = -1; void *decrement_counter(void *argv); void *increment_counter(void *argv); int main(int argc, char **argv) { printf("counter: %d/n", counter); pthread_t thd1, thd2; i...
1
#include <pthread.h> pthread_cond_t space_available = PTHREAD_COND_INITIALIZER; pthread_cond_t data_available = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int buffer[11]; int front = 0, rear = 0; void *produce() { int i = 0; while (1) { ...
0
#include <pthread.h> { int id; int nproc; } parm; char message[100]; pthread_mutex_t msg_mutex = PTHREAD_MUTEX_INITIALIZER; int token = 0; void* greeting(void *arg) { parm *p = (parm *) arg; int id = p->id; int i; if (id != 0) { while (1) { pthread_mutex_lock(&msg_mutex); if...
1
#include <pthread.h> char *word; int count; struct dict *next; } dict_t; pthread_mutex_t mutex; pthread_mutex_t wordmut; FILE *infile; dict_t* wd; char * make_word( char *word ) { return strcpy( malloc( strlen( word )+1 ), word ); } dict_t * make_dict(char *word) { dict_t *nd = (d...
0
#include <pthread.h> { double *a; double *b; double sum; int veclen; } DOTDATA; DOTDATA dotstr; pthread_t callThd[4]; pthread_mutex_t mutexsum; void *dotprod(void *arg) { int i, start, end, len ; long offset; double mysum, *x, *y; offset = (long)arg; ...
1
#include <pthread.h> pthread_mutex_t mutex; pthread_cond_t cond; void * test(void * arg) { pthread_mutex_lock(&mutex); for (int i = 0; i < 10; ++i) { printf("T1 : %d\\n", i); sleep(1); if (i == 5) pthread_cond_wait(&cond, &mutex); } pthread_mutex_unlock(...
0
#include <pthread.h> static void dump_line(char * out, const char *addr, const int len) { int i; char temp[5]; strcat(out, "|"); for (i = 0; i < 16; i++) { if (i < len) { sprintf(temp, " %02X", ((uint8_t *) addr)[i]); strcat(out, temp); } e...
1
#include <pthread.h> struct x_pthread_create_control_block_s { pthread_mutex_t start_lock; volatile void *(*start)(void *); void *arg; }; static void x_pthread_create_commit(void *args, int *result) { x_pthread_create_control_block_t *control_block = (x_pthread_create_control_block_t *) arg...
0
#include <pthread.h> pthread_mutex_t lock_pista = PTHREAD_MUTEX_INITIALIZER; void * aviao(void * arg){ int i = *((int *) arg); while(1){ printf("%d: voando\\n",i); sleep(5); printf("%d: vai pousar\\n",i); pthread_mutex_lock(&lock_pista); printf("%d: po...
1
#include <pthread.h> int num; pthread_mutex_t mutex; pthread_cond_t cond; }my_sem_t; int queue[5]; my_sem_t blank_number, product_number; int my_sem_init(my_sem_t *sem, int pshared, int value) { sem->num = value; pthread_mutex_init(&sem->mutex, 0); pthread_cond_init(&sem->cond, 0); retu...
0
#include <pthread.h> static int ready = 0; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static void * mythr(void *ignore) { pthread_mutex_lock(&mutex); ready = 1; pthread_cond_signal(&cond); pthread_mutex_unl...
1
#include <pthread.h> int in = 0; int out = 0; int buff[10] = {0}; sem_t empty_sem; sem_t full_sem; pthread_mutex_t mutex; int producer_id = 0; int consumer_id = 0; int now_item = 0; void print() { int i; for(i = 0; i < 10; i++) printf("%d ", buff[i]); printf("\\n"); } void *producer()...
0
#include <pthread.h> int run_thread = 1; struct FIFO *f; void writer(void); void *writer_thread(void *data); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int main() { pthread_t awriter_thread; int i,j; short read_buf[8]; int n_out = 0; int sucess; f = fifo...
1
#include <pthread.h> int mouse_hook(int button, int x, int y, void *e) { (void)e; pthread_mutex_lock(&sgt_constructor()->mutex_preview); mouse(button, x, y); pthread_mutex_unlock(&sgt_constructor()->mutex_preview); return (1); }
0
#include <pthread.h> static int block_size = 512; struct signs { int length; char * signs; }; void append_sign_binary(struct signs * s, char sign){ if(sign == 0){ return; } if(sign == 1){ int byte = s->length / 1; int rem = s->length % 1; s->signs[byte] = s->signs[...
1
#include <pthread.h> pthread_mutex_t chopstick[5]; pthread_t philos[5]; void initialize() { int i; for(i=0;i<5;i++) pthread_mutex_init(&chopstick[i],0); } void* dinner(void *param) { int id=*((int*)param); int waittime; while(1) { waittime=rand()%5; printf("Philosopher %d...
0
#include <pthread.h> void init_matrix (int *matrix, int fils, int cols) { int i, j; for (i = 0; i < fils; i++) { for (j = 0; j < cols; j++) { matrix[i * cols + j] = 1; } } } int *matrix1; int *matrix2; int *matrixR; int matrix1_fils; int matrix1_cols; int matrix2_fils; int matrix2_col...
1
#include <pthread.h> int bufer [10]; pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER; void * productor(); void * consumidor(); int main (){ srand(time(0)); pthread_t h1,h2; pthread_mutex_lock(&m2); pthread_create(&h1,0,&productor,0); pthrea...
0
#include <pthread.h> pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int availA, availB; int *map; struct timeval start, end; FILE *fp2; void * increment_count(void *arg) { int i; char *letter = arg; availA = 1; availB = 0; ...
1
#include <pthread.h> static int get_linkstatu() { int fd; int offset; int ret=0; fd = open("/dev/rdm0", O_RDONLY); offset=0xB0110000; ioctl(fd, 0x6B0D, &offset); offset=0x80; ioctl(fd, 0x6B03, &offset); if(offset&(3<<28)) { ret=1; } ...
0
#include <pthread.h> int connfd; int threadId; } thread_data; pthread_mutex_t file_lock; void* processRequest(void* t){ thread_data* t_data = (thread_data*)t; int connfd = t_data->connfd; int threadId = t_data->threadId; char textBuf[160]; int readLen; while ( (readLen=Read(c...
1
#include <pthread.h> int variableCompartidaSuma = 0; int elementosPitagoricos[4] = {1, 2, 3, 4}; pthread_mutex_t mi_mutex; void* sumarValor (void* parametro){ int posArray; posArray = (intptr_t) parametro; printf("Sumando posicion = %d \\n", posArray); pthread_mutex_lock(&m...
0
#include <pthread.h> static pthread_mutex_t error_mutex = PTHREAD_MUTEX_INITIALIZER ; static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER ; static pthread_mutex_t verbose_mutex = PTHREAD_MUTEX_INITIALIZER ; static int xverbose_max_level=0; static int xdebug_max_level=0; stat...
1
#include <pthread.h> void *func(int n); void disp_philo_states(); void chopstickStates(int n); pthread_t philosopher[5]; pthread_mutex_t mutex,chopstickLock[5]; int eatCount[5] = {0,0,0,0,0}; HUNGRY, EATING, THINKING } philos_state; FREE = 0, IN_USE = 1 } Sticks; philos_state state[5];...
0
#include <pthread.h> sem_t sem_producer; sem_t sem_consumer; unsigned int count; unsigned int data[12]; int in; int out; pthread_mutex_t mutex; pthread_cond_t empty; pthread_cond_t full; } buffer_t; static buffer_t shared_buffer = { .count = 0, .in = ...
1
#include <pthread.h> static struct scap_tasks * scap_tasks = 0; void scapremedy_process_init() { assert ( scap_tasks == 0 ); scap_tasks = rscap_alloc(sizeof ( *scap_tasks )); scap_tasks->tasks = 0; scap_tasks->task_id_counter = 1; pthread_mutex_init(&scap_tasks->mx, 0); } struct scap_ta...
0
#include <pthread.h> { int adj_n; int pre; int min_d; int *adj; int *w; }vertex; pthread_mutex_t mutex; pthread_mutex_t *mutex_v; vertex *vertices; int *work_q; int vertex_n, head, tail, terminate, count, qsize, notused; double diff(struct timespec start, struct timespec end){ double temp;...
1
#include <pthread.h> pthread_mutex_t forkLock[10000000]; int numOfTimesToEat; int philosophers; void dinning(int numOfPhil, int numOfEating) { numOfTimesToEat = numOfEating; philosophers = numOfPhil; pthread_t people[numOfPhil]; for (long i = 0; i <= numOfPhil; i++) { ...
0
#include <pthread.h> int size = 100; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; struct matrixs { int matrixA[500][500]; int matrixB[500][500]; int solution[500][500]; long id; }; void fillArrays(struct matrixs *); void printArray(struct matrixs *); void *multiply( void *param); ...
1
#include <pthread.h> pthread_mutex_t muta; pthread_cond_t cv; int cnt; pthread_t threads[10]; void *inc_cnt(void *arg) { int i; int idx = (*(int *) arg); for (i = 0; i < 10 +10; i++) { sleep(1); if (cnt > 10) { pthread_exit(0); } pthread_mutex_lock(&muta); cnt++; if (cnt == 1...
0
#include <pthread.h> struct atomicqueueitem { void *object; struct atomicqueueitem *next; }; struct atomicqueue { struct atomicqueueitem *head; pthread_mutex_t mutex; }; struct atomicqueue *atomicqueue_create() { struct atomicqueue *queue = malloc(sizeof(struct atomicq...
1
#include <pthread.h> static int si_init_flag = 0; static int s_conf_fd = -1; static struct sockaddr_un s_conf_addr ; static int s_buf_index = 0; static char s_buf_pool[4][(16384)]; static pthread_mutex_t s_atomic; static char CONF_LOCAL_NAME[16] = "/tmp/rptClient"; inline int rptSockSetLocal...
0
#include <pthread.h>extern void __VERIFIER_assume(int); extern void __VERIFIER_error() ; void __VERIFIER_assert(int expression) { if (!expression) { ERROR: __VERIFIER_error();}; return; } const int SIGMA = 3; int *array; int array_index=-1; pthread_mutex_t mutexes[SIGMA]; pthread_mutex_t mu...
1
#include <pthread.h> static pthread_mutex_t text_message_mutex = PTHREAD_MUTEX_INITIALIZER; static char text_message[300]; int setup_text_message(void) { if (pthread_mutex_init(&text_message_mutex, 0) != 0) { return error(ERROR, "Unable to create usb mutex...
0
#include <pthread.h> STACK stack_init(size_t capacity); bool stack_destroy(STACK *s); bool stack_push(STACK s, uintptr_t *item); bool stack_pop(STACK s, uintptr_t *item); bool stack_look(STACK s, uintptr_t *item); size_t stack_size(STACK s); bool stack_empty(STACK s); bool stack_full(STACK s); ...
1
#include <pthread.h> static void *jit_jni_trampoline(struct compilation_unit *cu) { struct vm_method *method = cu->method; struct buffer *buf; void *target; target = vm_jni_lookup_method(method->class->name, method->name, method->type); if (!target) { signal_new_exception(vm_jav...
0
#include <pthread.h> void update_full_db(double point[], double F, double *G, int n, int surrogate) { int PROBDIM = data.Nth; int i, pos; pthread_mutex_lock(&full_db.m); pos = full_db.entries; full_db.entries++; pthread_mutex_unlock(&full_db.m); if (full_db.entry[pos].point == 0) full_db....
1
#include <pthread.h> struct gftp_request { unsigned int cancel : 1, stopable : 1; void *protocol_data; }; struct gftp_transfer { struct gftp_request * fromreq; unsigned int started : 1, cancel : 1, ready : 1, done : 1; int nu...
0
#include <pthread.h> int w, h; v2df zero = { 0.0, 0.0 }; v2df four = { 4.0, 4.0 }; v2df nzero; double inverse_w; double inverse_h; char *whole_data; int y_pick; pthread_mutex_t y_mutex = PTHREAD_MUTEX_INITIALIZER; static void * worker(void *_args) { char *data; double x, y; int ...
1
#include <pthread.h> pthread_cond_t state_cv; pthread_mutex_t state_mx; enum {WAITING, WORKING, SHUTTING} state = WAITING; pthread_t comm; static struct camera_control_block ccb; int sfd; int cfd; int frame_callback(struct camera_control_block *ccb, struct frame_type *frame) { (void) ccb...
0
#include <pthread.h> { double *a; double *b; double sum; int veclen; } DOTDATA; DOTDATA dotstr; pthread_t callThd[4]; pthread_mutex_t mutexsum; void *dotprod(void *arg) { int i, start, end, len ; long offset; double mysum, *x, *y; offset = (long)arg...
1
#include <pthread.h> static pthread_t tid; int Loop; int Debug; static struct{ char buf[512]; pthread_mutex_t lock; int len; } Recv_Buf; static struct { int local_fd; struct sockaddr_in svr_addr; } Sock; char name[32]; int pos_x; int pos_y; } Player; st...
0
#include <pthread.h> struct button { int id; uint16_t x; uint16_t y; uint16_t w; uint16_t h; char *str; bool pressed; struct button *next; }; static struct button *buttons = 0; static pthread_mutex_t mutex; static int current_id = 0; static void(*user_callback)(int)...
1
#include <pthread.h> char glog_dir[LEN]; char* snapTime(char* buf, int len){ time_t curtime; struct tm *loc_time; curtime = time (0); loc_time = localtime (&curtime); strftime (buf, len, "%H:%M:%S", loc_time); return buf; } char* snapClockTime(char* buf, int len){ struct timespec sna...
0
#include <pthread.h> int bb_buf[100]; pthread_mutex_t mutex; pthread_cond_t EscFromFull; pthread_cond_t EscFromEmpty; int point = 0; int a = 0; void* bb_get(void* t) { int i; pthread_mutex_lock(&mutex); while(point == 0) { pthread_cond_wait(&EscFromEmpty, &mutex); } printf("%d\\...
1
#include <pthread.h> const int MAX_BITS = 8; const int SIGNIFICATIVE_BITS = 6; const int MAX_RGB = 255; struct HSV * LUT_RGB2HSV [64][64][64]; int isInitTableHSV; pthread_mutex_t mutex; void rgb2hsv_wiki (double r, double g, double b, double *H, double *S, double *V) { double min, max; ...
0
#include <pthread.h> static char wordBuffer[(1000000)][WORD_LENGTH+1]; static int bufferSize = 0; pthread_mutex_t bufferUse; bool fileProccessing = 1; int main(int argc, char* argv[]) { if(argc != 3) { printf("Invalid arguments.\\n" "Number of child threads (1 or greater)\\n" "File...
1
#include <pthread.h> const int MAX_THREADS = 1024; void* trap(void* rank); void get_args(int argc, char* argv[] ); void usage(char* prog_name); long thread_count; double global_estimate, a, b, h; long n; pthread_mutex_t mutex; int main(int argc, char* argv[] ) { long thread; pthread_t* thr...
0
#include <pthread.h> pthread_mutex_t m; void *odd(void *max) { int i; struct timeval tp; pthread_mutex_lock(&m); for (i = 0; i < 10; i++) { printf("odd %d\\n", i); sleep(1); } pthread_mutex_unlock(&m); } void *even(void *max) { int i; struct timeval tp; pthread_mute...
1
#include <pthread.h> pthread_mutex_t fork_mutex[5]; pthread_mutex_t eat_mutex; pthread_cond_t space_avail = PTHREAD_COND_INITIALIZER;; int num_diners=0; main() { int i; pthread_t diner_thread[5]; int dn[5]; void *diner(); pthread_mutex_init(&eat_mutex, 0); for (i=0;i<5;i++) pthr...
0
#include <pthread.h> pthread_mutex_t mux; pthread_cond_t cond; int is_locked; int wait_count; int usage_count; } _EVENT; int _tr50_event_create(void **handle) { _EVENT *evt; if (handle == 0) { return ERR_TR50_BADHANDLE; } if ((*handle = _memory_malloc(sizeof(_EVENT))) == 0) {...
1
#include <pthread.h> extern void *hash_flows; extern void *hash_flows2; void send_debulk_buffer(struct seg6_sock *sk, struct parser_ipv6_sr *bulk_sr, int debulk_len, char *debulk_data, int bulk_hdr_size) { int len, next_header = 41, offset = 0; struct parser_ipv6 *ip6hdr; struct pa...
0
#include <pthread.h> int asientos[10*3*4]; void * threadfunc(void *); pthread_mutex_t mutexes[10*3*4] = PTHREAD_MUTEX_INITIALIZER; int main(int argc, const char * argv[]) { srand(time(0)); pthread_t * compradores = (pthread_t *) malloc (sizeof(pthread_t) * 10); for (int i = ...
1
#include <pthread.h> int p; int r; } TInfo; int THREADS = 0; double* A; pthread_mutex_t s; void mergeSort_intercala(int p, int q, int r){ int i, j, k; double *B; B = (double *) malloc(sizeof(double) * (r-p+1)); for(i=p; i<=q; i++) B[i-p] = A[i]; for(j=r; j>q; j...
0
#include <pthread.h> char* fp_src; char* fp_dest; int src_fd; int dest_fd; char file_name[256]; } FilePair; int NUM_THREADS; int count; FilePair pairs[20]; pthread_cond_t buffer_empty; pthread_cond_t buffer_full; pthread_mutex_t lock; void producerBufferWrite(); void consumerBufferRe...
1
#include <pthread.h> void * runner (void *arg); struct args * allocate_struct ( int P ); pthread_t * allocate_tids ( int P ); struct args { long long start; long long last; FILE *fd; }; pthread_mutex_t lock; int P; long long count = 0; int main (int argc, char ** argv) { long long i, las...
0
#include <pthread.h> int var, cnt; pthread_mutex_t mtx; int randT() { return rand() % 10; } int randTexc(int i) { int x = randT(); while(x == i) x = randT(); return x; } void* doIt(void* arg) { int id = *(int*)arg; while(cnt < 20) { pthread_mute...
1
#include <pthread.h> ssize_t n; int sockfd; int TotalNum = 0; static int Connect = 0; uint8_t TotalNum_buf[2] = {0}; int poll_flag = 0; static uint8_t flag[5] = {0}; static uint8_t buf[N] = {0}; char *getip = 0; const char* ip_1 = "192.168.1.233"; const char* ip_2 = "127.0.0.1"; pthread_t thread_...
0
#include <pthread.h> int numtasks; int npoints; int times; int debug=0; pthread_mutex_t* mutex; pthread_cond_t* cond; pthread_barrier_t barrier_calc; pthread_t thread_id; int thread_num; int thread_step; int thread_first; } ThreadData; int **states; double *values, *o...
1
#include <pthread.h> struct msg { struct msg *next; int num; }; struct msg *head; pthread_cond_t has_product = PTHREAD_COND_INITIALIZER; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; void *consumer(void *p) { struct msg *mp; while(1) { pthread_mutex_lock(&lock);...
0
#include <pthread.h> pthread_t start_thread(void *func, int *arg) { pthread_t thread_id; int rc; printf("In main: creating thread\\n"); rc = pthread_create(&thread_id, 0, func, arg); if (rc) { printf("ERROR; return code from pthread_create() is %d\\n", rc); exit(-1); } return(thread...
1
#include <pthread.h> extern char **environ; pthread_mutex_t env_mutex; static pthread_once_t init_done = PTHREAD_ONCE_INIT; static void thread_init(void) { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex...
0
#include <pthread.h> int count =0; int lastPrime =0; char *flags; pthread_mutex_t lock; void* pp(void *rank); int main(int argc, char* argv[]){ long n =100; long p =100; flags = malloc(sizeof(char) * ((n - 1)/2)); if (!flags) { printf("Not enough memory.\...
1
#include <pthread.h> int cnt; int pos; unsigned char buff[1024]; pthread_mutex_t mtx; pthread_cond_t cv; } pipe_t; pipe_t *pipe_open() { pipe_t *p = malloc(sizeof(pipe_t)); if (p) { p->pos = 0; p->cnt = 0; pthread_mutex_init(&p->mtx, 0); ...
0
#include <pthread.h> void ports_end_rpc (void *port, struct rpc_info *info) { struct port_info *pi = port; pthread_mutex_lock (&_ports_lock); if (info->notifies) _ports_remove_notified_rpc (info); *info->prevp = info->next; if (info->next) info->next->prevp = info->prevp; pi...
1
#include <pthread.h> char string[1000]; char ready_string[1000]; int kill_threads; int fd; pthread_mutex_t lock; pthread_mutex_t lock2; void* fun1(void* arg){ while(1){ pthread_mutex_lock(&lock); if(kill_threads == 0){ pthread_mutex_unlock(&lock); break; } pthread_mute...
0
#include <pthread.h> unsigned long total_io_interval = 0; unsigned long total_req_inqueue_time = 0; long total_ios = 0; long total_req = 0; pthread_mutex_t statistics_mutex; pthread_t statistics_thread_id; long clks_per_sec; void* log_time_statistics(void* arg){ DPRINTF("Log Statistics Threa...
1
#include <pthread.h> struct netent *getnetbyname(const char *name) { char *buf = _net_buf(); if (!buf) return 0; return getnetbyname_r(name, (struct netent *) buf, buf + sizeof(struct netent), NET_BUFSIZE); } struct netent *getnetbyname_r(const char *name, struct netent *result, ...
0
#include <pthread.h> pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER; { int min; int max; int ligne; int colonne; int nLigne; int somme; int **matrix; } arguments; void *thread(void *arg){ int s=0; arguments *args = (arguments *) arg; pthread_mutex_lock(&mutex); int *newligne=...
1
#include <pthread.h> int thID; int min; int max; } arg; int **a; int N, M, T; pthread_mutex_t mx; int contador = 0; void tres (arg *args) { int i, j; int c=0; for (i=args->min; i<args->max; i++){ for (j=0; j<M; j++){ if (a[i][j] == 3) c=c+1; } } pthrea...
0
#include <pthread.h> int buffer[20]; int pointer = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond1 = PTHREAD_COND_INITIALIZER; pthread_cond_t cond2 = PTHREAD_COND_INITIALIZER; int nitens() { sleep(1); return(rand() % 20 + 1); } void insere_item(int item) { ...
1
#include <pthread.h> static pthread_mutex_t lock; pthread_t thread_1; pthread_t thread_2; int a = 0; void* func_1() { pthread_mutex_lock(&lock); pthread_mutex_lock(&lock); printf("thread fun1() lock\\n"); a = 2; printf("thread fun1() a= %d\\n", a); printf("thread fun1() unlock\\n");...
0
#include <pthread.h> struct prodcons{ int buffer[16]; int read_pos; int write_pos; pthread_mutex_t lock; pthread_cond_t not_empty; pthread_cond_t not_full; }; struct prodcons g_buffer; void init(struct prodcons* buf){ pthread_mutex_init(&buf->lock,0); pthread_cond_init(&buf->not_emp...
1
#include <pthread.h> pthread_t tid[2]; int counter; pthread_mutex_t lock; void* doSomeThing1(void *arg) { int j = 0; printf("%s entering...", __func__); fflush(stdout); while(j < 10) { pthread_mutex_lock(&lock); printf("%s done\\n", __func__); if(j == ...
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 = malloc(sizeof(str...
1
#include <pthread.h> void prendre(int *c, struct Piece *stock, int i) { int compt = *c; int pos = index[i]; if ((compt == 0) && ((testOp[i](Anneau[pos], 1)) || (testOp[i](Anneau[pos], 2)) || (testOp[i](Anneau[pos], 3)))) { stock[0] = Anneau[pos]; Anneau[pos] = PieceNull; ...
0
#include <pthread.h> struct ListNode { int data; struct ListNode* next; struct ListNode* prev; }; void append(struct ListNode* list, int data); void printList(struct ListNode* list); void printElement(struct ListNode* node); void delete(struct ListNode* node); struct ListNode * head; ...
1
#include <pthread.h> struct thread_data { pthread_mutex_t *mutex; pthread_cond_t *cond; const unsigned trough_capacity; const unsigned delay; volatile int trough_quantity; volatile int iters_rem; }; static char *app_name_; static void * mare_thread_func (void *tdata) { stat...
0
#include <pthread.h> extern FILE *fileout_basicmath; extern pthread_mutex_t mutex_print; int main_basicmath(void) { double a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0; double a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0; double a3 = 1.0, b3 = -3.5, c3 = 22.0, d3 = -31.0; double a4 = 1.0...
1
#include <pthread.h> pthread_mutex_t counter = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t waitLeft = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t waitRight = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t tunnelWaitLeft = PTHREAD_COND_INITIALIZER; pthread_cond_t tunnelWaitRight = PTHREAD_COND_INITIALIZ...
0
#include <pthread.h> void* value; int key; volatile struct _setos_node* next; pthread_mutex_t lock; } setos_node; setos_node* head; int setos_init(void) { head = (setos_node*) malloc(sizeof(setos_node)); head->next = 0; head->key = INT_MIN; if (pthread_mutex_init(&head->lock...
1
#include <pthread.h> pthread_mutex_t shop_mutex; pthread_mutex_t nextCustomer_mutex; pthread_mutex_t barberSleep_mutex; pthread_cond_t barberSleepStatus_cond; pthread_cond_t barberWorkStatus_cond; int numCustomers = 0; int barberSleeping = 0; int haircutTime = 0; void get_hair_cu...
0