text
stringlengths
192
6.24k
label
int64
0
1
#include <pthread.h> enum {ARRAY_SIZE = 1000,}; const unsigned long int LOOP_ITERATIONS = (1 << 25); pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; pthread_barrier_t b; int global_array[ARRAY_SIZE]; void *reader(void *arg) { int tmp = *(int *)&m; pthread_barrier_wait(&b); wh...
1
#include <pthread.h> void * runner1(void * args) { int * a = (int *) args; int i, sum=0; for (i = 0; i < *a; i+=2){ sum += i; } printf("Even Sum: %d\\n", sum); } void * runner2(void * args) { int * a = (int *) args; int i, sum=0; for (i = 1; i < *a; i+=2){ sum += i; } printf("Odd Su...
0
#include <pthread.h> int g_Flag = 0; pthread_t thrdid1,thrdid2; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond=PTHREAD_COND_INITIALIZER; void* thrd_start_routine(void* v) { pthread_detach(pthread_self()); pthread_mutex_lock(&mutex); if(g_Flag == 2) pthread_cond_sig...
1
#include <pthread.h> int key = 2; struct arguments { int threadName; pthread_mutex_t *lock; pthread_cond_t *cond; }; void *do_work(void *arg); int main(int argc, char **argv) { int numThreads = atoi(argv[1]); pthread_t worker_thread[numThreads]; pthread_mutex_t mutex; pthread...
0
#include <pthread.h> struct mtqueue* mtqueue_new() { struct mtqueue *mtqueue; mtqueue = malloc(sizeof(struct mtqueue)); if (!mtqueue) return 0; pthread_mutex_init(&mtqueue->lock, 0); pthread_mutex_init(&mtqueue->mutex, 0); pthread_cond_init(&mtqueue->cond, 0); ...
1
#include <pthread.h> char globalChar; int state = 0; int globalFlag = 0; int printFlag = 0; pthread_t tid[3]; pthread_mutex_t lock1, lock2, lock3, lockMain; void* thread1(void *arg) { int i = 1; int tempInt; FILE *input = fopen("hw5-1.in", "r"); while(i == 1 && globalFlag == 0) { pthrea...
0
#include <pthread.h> struct threadArgs{ int* numbers; long threadId; int size; }; struct threadReturnValue{ int number; long threadId; struct threadReturnValue* nextPtr; }; pthread_mutex_t mutexModify; int selectNumber; void removeNotPrimes(int selected, int* numbers,int size,long thr...
1
#include <pthread.h> struct foo { int f_count; pthread_mutex_t f_lock; int f_id; }; static struct foo *g_fp = 0; struct foo *foo_alloc(int id) { struct foo *fp; if((fp = malloc(sizeof(struct foo))) != 0){ fp->f_count = 1; fp->f_id = id; if(pthread_mutex...
0
#include <pthread.h> int row; int col; }parameters; int sudokoSolution1[9][9] = { {6, 2, 4, 5, 3, 9, 1, 8, 7}, {5, 1, 9, 7, 2, 8, 6, 3, 4}, {8, 3, 7, 6, 1, 4, 2, 9, 5}, {1, 4, 3, 8, 6, 5, ...
1
#include <pthread.h>extern void __VERIFIER_error() ; int element[(800)]; int head; int tail; int amount; } QType; pthread_mutex_t m; int __VERIFIER_nondet_int(); int stored_elements[(800)]; _Bool enqueue_flag, dequeue_flag; QType queue; int init(QType *q) { q->head=0; ...
0
#include <pthread.h> pthread_mutex_t mutex; pthread_t threads[4]; sem_t sems[4]; char *file_name[] = {"1.txt", "2.txt", "3.txt", "4.txt"}; FILE *files[4]; int file_id = 0; int cow = 0; void * func() { for (int m = 0; m < 20; m++) { for (int i = 0; i < 4; i++) { ...
1
#include <pthread.h> int webSockState; unsigned long initId; struct mg_connection *conn; } tWebSockInfo; static pthread_mutex_t sMutex; static tWebSockInfo *socketList[(256)]; static void send_to_all_websockets(const char * data, int data_len) { int i; for (i=0;i<(256...
0
#include <pthread.h> char** theArray; pthread_mutex_t **mutexArray; void* ServerEcho(void *args); int main(){ printf("creating mutex array \\n"); theArray=malloc(100*sizeof(char)); for (int i=0; i<100;i++){ theArray[i]=malloc(100*sizeof(char)); sprintf(theArray[...
1
#include <pthread.h> void *func(int n); pthread_t philosopher[5]; pthread_mutex_t chopstick[5]; void *func(int n) { printf("Philosopher %d is thinking \\n",n); pthread_mutex_lock(&chopstick[n]); pthread_mutex_lock(&chopstick[(n+1)%5]); printf("Philosopher %d is eating now\\n",n); ...
0
#include <pthread.h> void* clnt_connection(void * arg); void send_message(char* message, int len); void error_handling(char * message); int clnt_number=0; int clnt_socks[10]; pthread_mutex_t mutx; int main(int argc, char **argv) { int serv_sock; int clnt_sock; struct sockaddr_in serv_addr;...
1
#include <pthread.h> int pwstart(void) { pthread_attr_t attr_t; pthread_attr_init(&attr_t); pthread_attr_setdetachstate(&attr_t, PTHREAD_CREATE_DETACHED); return pthread_create(&CONTRAL.thread_key, &attr_t, BATTERY.server, 0); } void *pwserver(void *args) { struct timespec t...
0
#include <pthread.h> { int id; int sleep_time; } parm; pthread_mutex_t msg_mutex = PTHREAD_MUTEX_INITIALIZER; char message[128]; int token = 0; void *hello_world(void *arg) { parm *p = (parm *) arg; int id = p->id; int sleep_time = p->sleep_time; int i; if (id != 0) { w...
1
#include <pthread.h> QUEUE queue_init(size_t capacity); bool queue_destroy(QUEUE *q); bool queue_put(QUEUE q, uintptr_t *item); bool queue_get(QUEUE q, uintptr_t *item); bool queue_look(QUEUE q, uintptr_t *item); size_t queue_size(QUEUE q); bool queue_empty(QUEUE q); bool queue_full(QUEUE q); s...
0
#include <pthread.h> pthread_cond_t taxiCond = PTHREAD_COND_INITIALIZER; pthread_mutex_t taxiMutex = PTHREAD_MUTEX_INITIALIZER; int travelerCount = 0; void *traveler_arrive(void *name){ printf("Traveler %s needs a taxi now!\\n", (char *)name); pthread_mutex_lock(&taxiMutex); travelerCoun...
1
#include <pthread.h> volatile int running_threads = 0; void *library; void push(struct Stack **head, char name[]) { struct Stack *tmp = (struct Stack *)malloc(sizeof(struct Stack)); if (tmp == 0) { exit(1); } tmp->next = *head; strcpy(tmp->fileName, "./Files/"); strcat(tmp->fileName, n...
0
#include <pthread.h> static int log_level = SLOG_DEBUG; static const char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static char *log_data = 0; static int log_in, log_out, log_size; static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIA...
1
#include <pthread.h> pthread_mutex_t help_mutex; pthread_mutex_t count_mutex; sem_t TA_sem; sem_t student_sem; int number_waiting; int go_home; long nsecSleep; int numberOfIterations; } sleepAndCount; void* simulate_student(void* param); void* simulate_TA(void* param); int main(int arg...
0
#include <pthread.h> extern void send_msg(const char* ip, int port, const char* msg); extern volatile sig_atomic_t interrupt; extern const char* RESPONSE; extern void LLclear(); extern void LLfixDuplicateIPs(); extern pthread_mutex_t ll_mutex; void* sendRequest(void* arg){ char ip[IP_MAX]="1...
1
#include <pthread.h> int runStatus = RUN; int receivedDataStatus = NO_NEW_DATA; char sentData[DATA_LEN] = {'\\0'}; char receivedData[DATA_LEN] = {'\\0'}; pthread_mutex_t mutexData; pthread_mutex_t mutexStop; void destroyMutexes() { pthread_mutex_destroy(&mutexStop); pthread_mute...
0
#include <pthread.h> int nitems; struct { pthread_mutex_t mutex; int buff[100000]; int nput; int nval; } shared = { PTHREAD_MUTEX_INITIALIZER }; void * produce(void *); void * consume(void *); void consume_wait(int); int main(int argc, char ** argv) { int i, nthreads, count[100]; pthre...
1
#include <pthread.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static void *thread_func1(void *ignored_argument) { int s; printf("\\n %s: \\n",__func__); pthread_mutex_lock(&mutex); printf("Thread 1 acquire mutex \\n"); pthread_mutex_unlock(&mutex); printf("Thread 1 releases mutex...
0
#include <pthread.h> void terminal_init ( void ) { return; } void terminal_exit ( void ) { return; } void terminal_update ( void ) { float timestamp; if( DEBUG ) { printf("\\r"); if( datalog.enabled ) printf( " Log %s: ", datalog.dir ); else printf( " - - - - " ); t...
1
#include <pthread.h> int arg_port, numthreads; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int sockfds[256]; int numsock = 0; int numconns = 0; char whois_greet[] = "% This is the RIPE Database query service.\\n% The objects are in RPSL for...
0
#include <pthread.h> struct thd_data_t { pthread_mutex_t mutex; int found; int val; int start, stop; }; struct thd_data_t data_x = { .mutex = PTHREAD_MUTEX_INITIALIZER, .found = 0, .val = -1, .start = 10000, .stop = 20000, }; struct thd_data_t data_y = { ...
1
#include <pthread.h> struct products{ int buffer[2]; pthread_mutex_t lock; int writepos; int readpos; pthread_cond_t not_full; pthread_cond_t not_empty; }; struct products buffer; void init(struct products *prodc){ pthread_mutex_init(&(prodc->lock), 0); pthread_cond_init(&(pr...
0
#include <pthread.h> static int num = 0; static pthread_mutex_t mut_num = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond_num = PTHREAD_COND_INITIALIZER; void *is_prime(void *p) { int i, n, flag; while(1) { pthread_mutex_lock(&mut_num); while(num == 0) { pthread_cond_wait...
1
#include <pthread.h> int nbLignes; int nbMsg; } Parametres; int nbThreads; pthread_mutex_t mutex[20]; void thdErreur(int codeErr, char *msgErr, void *codeArret) { fprintf(stderr, "%s: %d soit %s \\n", msgErr, codeErr, strerror(codeErr)); pthread_exit(codeArret); } void deman...
0
#include <pthread.h> struct rotation_history_ring_buffer_t { uint32_t ring_index; uint32_t ring_size; struct pose_t ring_data[1024]; }; struct rotation_history_ring_buffer_t location_history; pthread_mutex_t pose_mutex; struct pose_t get_rotation_at_timestamp(uint32_t timestamp...
1
#include <pthread.h> bool not_end = 1; char buffer[513]; char* args[64]; bool background = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t condition_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER; pid_t back_pid = -1...
0
#include <pthread.h> pthread_mutex_t* mutexes; char** messages; void* Send_msg(void* rank); int* messages_available; long thread_count; void Get_args(int argc, char* argv[]); void Usage(char* prog_name); int main(int argc, char* argv[]) { long thread; long mutex_index; pthread_t* thread_hand...
1
#include <pthread.h> pthread_t prod[8]; pthread_t kons[8]; pthread_mutex_t blokada; int bufor; int produkcja; void *producent (void *i) { int prod=0; int nr=((int) i) + 1; while(1) { if (produkcja==800 && bufor == 0) { printf("Producent %d wyprodukowal %d produktow.\\n",nr,prod); ...
0
#include <pthread.h> void *method_thread_1(void *); void *method_thread_2(void *); void *method_thread_3(void *); pthread_t thread_3; void sig_handler(int sig); int isStopNow = 0; pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cv; pthread_t thread_1, thread_2; int main(){ sigset...
1
#include <pthread.h> pthread_mutex_t finished_mutex = PTHREAD_MUTEX_INITIALIZER; { int thread; int nr; } msg_t; msg_t finished = {-1, -1}; void *func(void *arg) { int thread_number = *((int *)arg), limit = 20, current = 3, a = 1, b = 1, c ...
0
#include <pthread.h> long long n = 100000; int flag; double sum; int num_of_threads; pthread_mutex_t mutex; void* thread_sum(void* rank); int main(int argc,char* argv[]) { num_of_threads = strtol(argv[1],0,10); pthread_t* threads = (pthread_t*) malloc(sizeof(pthread_t)*num_of_threads); pthr...
1
#include <pthread.h> sem_t empty,full; pthread_mutex_t mutex; struct prodcons { int buf[5]; int tid[5]; char *time[5]; int readpos, writepos; }; struct prodcons buffer; void init(struct prodcons *b) { b->readpos = 0; b->writepos = 0; } int producer_id=0,consumer_id=0; void *Produ...
0
#include <pthread.h> struct buffer { int array[10]; unsigned int front; unsigned int rear; pthread_mutex_t m; }queue; pthread_cond_t queue_full = PTHREAD_COND_INITIALIZER; pthread_cond_t queue_empty = PTHREAD_COND_INITIALIZER; void *puta(void*arg) { int i=2000; static int j=10; srand(1...
1
#include <pthread.h> struct s { int datum; struct s *next; } *A, *B; void init (struct s *p, int x) { p -> datum = x; p -> next = 0; } pthread_mutex_t A_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t B_mutex = PTHREAD_MUTEX_INITIALIZER; void *t_fun(void *arg) { pthread_mutex_lock...
0
#include <pthread.h> void instruction_register(void *not_used){ pthread_barrier_wait(&threads_creation); while(1){ pthread_mutex_lock(&control_sign); if(!cs.isUpdated){ while(pthread_cond_wait(&control_sign_wait,&control_sign) != 0); ...
1
#include <pthread.h> pthread_mutex_t* mutex_pth; void* threadProcess(void *arg){ int* alea_test ; *alea_test = (int) (10*((double)rand())/ 32767); int* arg_test = (int*) arg; pthread_t thread_tmp= pthread_self(); pthread_mutex_lock(mutex_pth); *arg_test += *alea_test; printf("%d | %d |...
0
#include <pthread.h> static pthread_mutex_t lock; static void *threadfunc(void *arg) { pthread_mutex_lock(&lock); printf("locked and thread over\\n"); pthread_exit(0); } int main(int argc, char *argv[]) { int retcode = 0; pthread_t thid; pthread_mutexattr_t attr; ...
1
#include <pthread.h> struct mon_time_entry { void *(*callback)(void *); void *args; int flags; time_t time; int iter; int delay; struct mon_time_entry *next; struct mon_time_entry *prev; }; static void *mon_time_run(void *args); static void mon_time_dump(void); static pt...
0
#include <pthread.h> int stoj = 0; pthread_mutex_t stoj_mutex = PTHREAD_MUTEX_INITIALIZER; int krabice = 0; sem_t krabice_sem; int prenesene = 0; pthread_mutex_t prenesene_mutex = PTHREAD_MUTEX_INITIALIZER; int ulozene = 0; pthread_mutex_t ulozene_mutex = PTHREAD_MUTEX_INITIALIZER; int skla...
1
#include <pthread.h> { int value; struct cell *next; } *cell; { int length; cell first; cell last; } *list; list add (int v, list l) { cell c = (cell) malloc (sizeof (struct cell)); c->value = v; c->next = 0; if (l == 0){ l = (list) malloc (sizeof (struct list)...
0
#include <pthread.h> static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static void *func(void *arg) { struct timespec spec = {0}; clock_gettime(CLOCK_REALTIME, &spec); spec.tv_sec += 10; sleep (1); pthread_mutex_timedlock(&lock, &spec); printf("slave thread\\...
1
#include <pthread.h> static FILE *log; static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; void log_init(void) { log = fopen(joinfs_context.logpath, "w+"); if(!log) { printf("---ERROR---Open log file failed, path:%s\\n", joinfs_context.logpath); exit(1); } } void log_destro...
0
#include <pthread.h> int duree_sommeil; int do_wakeup; pthread_cond_t cond; } simu_proc_t; static simu_proc_t *simu_procs; static pthread_mutex_t simu_mutex; static int simu_nbprocs; static int current_timespeed = 1; static int system_ticks = 1; static int running = 1; vo...
1
#include <pthread.h> double *in_circle; pthread_mutex_t *in_circle_lock; int threadID; long long num_tosses; }thread_data; void *toss_thread(void *threadD); int main(int argc, char const *argv[]) { int i; double in_circle = 0; long long number_of_tosses; if (argc == 2) { number_of_toss...
0
#include <pthread.h> struct arg{ int numThreads; int port; char * ip; int index; FILE *fp; }; pthread_mutex_t lock; void *run(void * arg){ int con_fd = 0; int ret = 0; struct sockaddr_in serv_addr; struct arg * pt = (struct arg *)arg; int numThreads = pt->numThread...
1
#include <pthread.h> float var_promedio=0; int var_minimo=0; int var_maximo=0; int longitud=0; pthread_mutex_t bloqueo; void *minimo(void *array) { int *ptr = (int*)array; int cont=0; pthread_mutex_lock(&bloqueo); var_minimo=ptr[0]; while(cont<longitud){ if (var_minimo>ptr[cont]){ var_...
0
#include <pthread.h> int source[30]; int minBound[3]; int maxBound[3]; int channel[3]; int th_id = 0; pthread_mutex_t mid; pthread_mutex_t ms[3]; 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[j]) ...
1
#include <pthread.h> int numtasks; int npoints; int times; int debug=0; pthread_mutex_t* mutex; pthread_cond_t* cond; pthread_t thread_id; int thread_num; int thread_step; int thread_first; } ThreadData; int **states; double *values, *oldval, *newval; int** create_array...
0
#include <pthread.h> struct element{ void* value; element *next; }; struct queue{ llist in; llist out; }; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; pthread_t id1, id2; struct queue* queue_new(void){ struct queue* new_queue ...
1
#include <pthread.h> { struct LinkTableNode * pNext; }tLinkTableNode; tLinkTableNode *pHead; tLinkTableNode *pTail; int SumOfNode; pthread_mutex_t mutex; }tLinkTable; tLinkTable * CreateLinkTable() { tLinkTable * pLinkTable = (tLinkTable *)malloc(sizeof(tLinkTable)); if...
0
#include <pthread.h> void handle_connection(int connfd) { char buffer[100]; int n, i = 0, fd; char c; while ((n = read(connfd, &c, 1)) > 0 && c!='\\n') buffer[i++] = c; buffer[i] = '\\0'; if ((fd = open(buffer, O_RDONLY))<0) { printf("file open error %s\\n", buffer)...
1
#include <pthread.h> int putenv_r(char *string); extern char **environ; pthread_mutex_t env_mutex = PTHREAD_MUTEX_INITIALIZER; int main(int argc, char *argv[]) { int ret = putenv_r("key1=myvalue friend"); printf("%d: mykey = %s\\n", ret, getenv("key1")); ret = putenv_r("key2=myvalue dog")...
0
#include <pthread.h> int num; unsigned long total; int flag; pthread_mutex_t m; pthread_cond_t empty, full; void *thread1(void *arg) { int i; i = 0; while (i < 2){ pthread_mutex_lock(&m); while (num > 0) pthread_cond_wait(&empty, &m); num++; pthread_mutex_unlock(&m...
1
#include <pthread.h> static struct termios old, new; static struct termios g_old_kbd_mode; static char *device = "default"; float buffer_null[1024]; int main(void) { int err; int j,k; num_det = 0; send = 0; Fs = 44100; durationdefaultsize = 0; mode = 2; num_jef[0...
0
#include <pthread.h> enum PhilState { THINKING, HUNGRY, EATING }; pthread_t thread; int id; int prio; int state; sem_t *forkLeft, *forkRight; struct philosopher_t *philLeft, *philRight; } Philosopher; sem_t *forks; sem_t forkLock; Philosopher *phils; int numPhils; void setTheTa...
1
#include <pthread.h> void malloc_and_forget(int size) { assert(size >= 0); (void)malloc(size); } static inline void strrev(char *str) { register int i; for (i = 0; i < strlen(str) / 2; i++) { str[i] ^= str[strlen(str) - i - 1]; str[strlen(str) - i - 1] ^= st...
0
#include <pthread.h> struct sockaddr_in server_addr; struct sockaddr_in client_addr; char operacion_a_realizar[4]; char mensaje_verificado[3]; char solucion[2]; int numero_clientes = 0; int rec; int sock_srv; pthread_mutex_t lock; void catchHijo() { printf("he pillado a un hijo murie...
1
#include <pthread.h> struct reconos_resource res[4]; struct reconos_hwt hwt; pthread_mutex_t mutex_a, mutex_b; pthread_cond_t condvar_a, condvar_b; pthread_t swthread; void * wait_on_condvar(void * arg){ while(1) { pthread_mutex_lock(&mutex_b); pthread_cond_wait(&condvar_b, &mutex_b...
0
#include <pthread.h> pthread_mutex_t cs_is_logging = PTHREAD_MUTEX_INITIALIZER; void cs_log_msg(int on_syslog, const char* format_s, va_list argv) { char msg[CS_MAX_LOG_MSG]; pthread_mutex_lock(&cs_is_logging); vsnprintf(msg, CS_MAX_LOG_MSG, format_s, argv); if(on_syslog) { sys...
1
#include <pthread.h> int pbs_asyrunjob_err( int c, char *jobid, char *location, char *extend, int *local_errno) { int rc; struct batch_reply *reply; unsigned int resch = 0; int sock; struct tcp_chan *chan = 0; if ((c < 0) || (jobid == 0) || (*jobid == '\\0')) { ...
0
#include <pthread.h> pthread_mutex_t mutex; pthread_cond_t cond; int avail=0; int consumed=0; int pause_thread(int pause_count){ int total=0; for(int i=0;i<pause_count;++i){ total++; } return total; } void * produce(void * arg){ int id = *((int *)arg); for...
1
#include <pthread.h> static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; struct node { int n_number; struct node *n_next; } *head = 0; static void cleanup_handler(void *arg) { printf("Cleanup handler of second thread./n")...
0
#include <pthread.h> int A [3][3] = { {1,1,1}, {2,2,2}, {3,3,3} }; int B [3][3] = { {1,1,1}, {2,2,2}, {3,3,3} }; int C [3][3]; struct v { int i; int j; }*data, param; static pthread_mutex_t mutex_matris; void *hesapla(void *param) { data = (struct v *)param; int satir = data->i; ...
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; for (;;) { pthread_mutex_lock(&lock); while (head =...
0
#include <pthread.h> void *write_msg(void* num_thread); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int k = 0; int fd; int main() { printf("Criando pipe para escrita...\\n"); mkfifo("pipe", 0644); fd = open("pipe", O_WRONLY); printf("Descritor do pipe: %d\\n\\n", ...
1
#include <pthread.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t queue_not_empty = PTHREAD_COND_INITIALIZER; pthread_cond_t queue_free_places = PTHREAD_COND_INITIALIZER; int queue[3]; int qlen = 0; void *producer( void *p) { int r; while(1) { r = rand() ...
0
#include <pthread.h> pthread_mutex_t mutexLock; int ascendNo[40] = {0}; static void *i_Write_Data(void *pData); static void *i_Print_Data(void *pData); int main(void) { unsigned char retVal = 0; int idx = 0; pthread_t threadId[2]; pthread_mutex_init(&mutexLock, 0); ...
1
#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 err,signo; for(;;) { err=sigwait(&mask,&signo); if(err!=0) err_exit(err,"sig...
0
#include <pthread.h> void *create_physics_update(void* arg) { float engine_torque = 0.0; float torque_drive = 0.0; float f_drive = 0.0; float f_drag = 0.0; float f_rr = 0.0; float f_long = 0.0; float acc = 0.0; float old_gear_ratio = 0.0; float v_max = compute_v_max...
1
#include <pthread.h> void send_ready_signal() { pthread_mutex_lock(&configs->lock); configs->flag = 1; pthread_cond_signal(&configs->cond); pthread_mutex_unlock(&configs->lock); } void load_configs() { int j = 0, i=0; char line[1024]; char *search = " ;\\n\\0", *token; ...
0
#include <pthread.h> pthread_mutex_t sleepMutex = PTHREAD_MUTEX_INITIALIZER; pthread_barrier_t sleepBarrier; void * lockSleepUnlock(void * c); void * sleepLockSleepUnlock(void * c); void * sleepTryLockSleepUnlock(void * c); int main(int argc, char *argv[]) { printf("Allocating memory for pthre...
1
#include <pthread.h> uint32_t speed; uint32_t mode; uint8_t bits; int fd; uint8_t chip_select; pthread_mutex_t lock; } SPIState; SPIState *spi_init(char *device, uint32_t mode, uint8_t bits, uint32_t speed, uint8_t chip_select) { int ret; SPIState *spi = (SPIState *) malloc(sizeof(SPIState...
0
#include <pthread.h> struct _results_t { size_t print_frequency_in_page_accesses; size_t expected_num_page_accesses; size_t test_file_size; int num_passes; int num_threads; char *mmap_advice_desc; char *desc; pthread_mutex_t mutex; size_t total_bytes_copied;...
1
#include <pthread.h> int num_threads = 1; int keys[100000]; pthread_mutex_t lock; int key; int val; struct _bucket_entry *next; } bucket_entry; bucket_entry *table[5]; void panic(char *msg) { printf("%s\\n", msg); exit(1); } double now() { struct timeval tv; getti...
0
#include <pthread.h> int init(void); int transmit(int,char*,char*); void* receive(void*); pthread_mutex_t count_mutex; int init() { int uart0_filestream = -1; uart0_filestream = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); if (uart0_filestream == -1) { printf("Error: Unable to o...
1
#include <pthread.h> static pthread_mutex_t socketMutex; static pthread_mutex_t strBufMutex; static sem_t signaller; static sem_t socketListSemaphore; static int* socketList; static char* buffer; static size_t strBufLen; static size_t socketListCursor = 0; static volatile int interrupted = 0; st...
0
#include <pthread.h> pthread_mutex_t no_wait, no_acc, counter; int no_of_readers=0; void reader(void *arg) { int id=*((int*)arg); printf("reader %d started\\n", id); while(1) { sleep(rand()%4); check_and_wait(id); read(id); } } void writer(void* arg) { int id=*((int*)arg); ...
1
#include <pthread.h> int quitflags; sigset_t mask; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t wait = PTHREAD_COND_INITIALIZER; void *thr_fun(void *arg); int main(void) { int err; sigset_t oldmask; pthread_t tid; sigemptyset(&mask); sigaddset(&mask, S...
0
#include <pthread.h> static pthread_t sp_tid; static int is_joined = 1; static int is_running = 0; struct sp_params { sigset_t sigmask; func_t processor; int copied; pthread_mutex_t mutex; pthread_cond_t cond; }; static void cleanup_sp_thread (void * arg) { extern int ...
1
#include <pthread.h> int num; unsigned long total; int flag; pthread_mutex_t m; pthread_cond_t empty, full; void *thread1(void *arg) { int i; i = 0; while (i < 3){ pthread_mutex_lock(&m); while (num > 0) pthread_cond_wait(&empty, &m); num++; printf ("produce .......
0
#include <pthread.h>extern void __VERIFIER_error() ; extern int __VERIFIER_nondet_int(); int idx=0; int ctr1=1, ctr2=0; int readerprogress1=0, readerprogress2=0; pthread_mutex_t mutex; void __VERIFIER_atomic_use1(int myidx) { __VERIFIER_assume(myidx <= 0 && ctr1>0); ctr1++; } void __V...
1
#include <pthread.h> { int first; int last; int validItems; char* data[40]; pthread_mutex_t lock; } circularQueue_t; void mvos_webToolsInitializeQueue(circularQueue_t *theQueue); int mvos_webToolsIsEmpty(circularQueue_t *theQueue); int mvos_webToolsPutItem(circularQueue_t ...
0
#include <pthread.h> void *iniciarTesteEnlace() { int te, tr; pthread_t threadEnviarDatagramas, threadReceberDatagramas; te = pthread_create(&threadEnviarDatagramas, 0, enviarDatagramas, 0); if (te) { printf("ERRO: impossivel criar a thread : enviarDatagramas\\n"); ...
1
#include <pthread.h> int count; pthread_mutex_t cont_mutex= PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; void *inc_thread (void *data) { while(1) { pthread_mutex_lock (&cont_mutex); pthread_mutex_lock (&cont_mutex); count++; printf("Inc: %d\\n", count); pthread_mutex_unlock (&cont_mu...
0
#include <pthread.h> void *sender_threads(void *arg) { unsigned char *packet; int len; int id, pid; id = *((int *) arg); for (;;) { sem_wait(&sem_queue); pthread_mutex_lock (&lock_queue); packet = dequeue(&p_queue, &len, &pid); pthread_mutex_unlock (&lock_queue); ...
1
#include <pthread.h> pthread_cond_t condition = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex; int storage = 0; int finish = 0; void* consumer(void* arg) { printf("Consumer[%x] thread started\\n", pthread_self()); while(1) { pthread_mutex_lock(&mutex); while(storage < 100) pthread...
0
#include <pthread.h> struct video_listener *listener = 0; void bepoppy8_init() { listener = cv_add_to_device(&front_camera, vision_func); STARTED = 0; NumWindows = 5; ForwardShift = 1.0; FOV = 100.0; WindowAngle = FOV/NumWindows; windowThreshold = 30; pthread_mutex_init(&navWi...
1
#include <pthread.h> int sem_getvalue(sem_t *restrict sem, int *restrict sval) { int result = 0; if (!sem || !sval) { result = EINVAL; } else if (!pthread_mutex_lock(&sem->mutex)) { *sval = sem->value; ...
0
#include <pthread.h> pthread_mutex_t verrou = PTHREAD_MUTEX_INITIALIZER; struct data { int *Tab1; int *Tab2; int *Resultat; int taille; int i; }; void * Som(void * par){ int *somme=(int *)malloc(sizeof(int)); pthread_t moi = pthread_self(); struct data *mon_D1 = (...
1
#include <pthread.h> int listenfd; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void web_child(int i, int sockfd) { int ntowrite, nread; char line[64], result[16384]; memset(line, 0, 64); for ( ; ; ) { if ((nread = read(sockfd, line, 64 - 1)) == 0) { printf("th...
0
#include <pthread.h> extern void init_scheduler(int); extern int scheduleme(float, int, int, int); FILE *fd; struct _thread_info { int id; float arrival_time; int required_time; int priority; }; double _global_time; float _last_event_time; pthread_mutex_t _time_lock; pthread_mutex_t _las...
1
#include <pthread.h> int start, end, threadID; } Param; int isPrime(int x){ if(x<=1){ return 0; } for(int i=2;i<x;i++){ if(x%i==0){ return 0; } } printf("%i is prime\\n",x); return 1; } int totalPrimes = 0; pthread_mutex_t ...
0