text
stringlengths
192
6.24k
label
int64
0
1
#include <pthread.h> pthread_mutex_t mutex; pthread_cond_t cond; int buffer = 0; void* producer(void* arg) { for(int i = 0; i < 5; ++i) { pthread_mutex_lock(&mutex); buffer = buffer + 1; printf("Buffer value in PRODUCER is : %d\\n", buffer); pthread_cond_signa...
1
#include <pthread.h> void exec(char * source, size_t len, char * cmd) { FILE * fp; fp = popen(cmd, "r"); char * buffer = malloc(len * sizeof(char)); while (fgets(buffer, len - 1, fp) != 0); pclose(fp); strcpy(source, buffer); free(buffer); } void query(char * dest, char * cm...
0
#include <pthread.h> int velkost; } Dlazdica; int pocetDlazdic = 0; int pozicia_na_umiestnenie = 0; int pozicia_na_zobratie = 0; Dlazdica *kopa[10]; int ulozeneDlazdiceMale = 0, ulozeneDlazdiceVelke = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condPomocnici...
1
#include <pthread.h> FILE *CreateReceiveFile(char *fileName, const char *folderName) { char filePath[4096]; struct stat st = { 0 }; if (stat(folderName, &st) == -1) { if (mkdir(folderName, 0777) == -1) return 0; } strcpy(filePath, folderName); strcat(...
0
#include <pthread.h> const char *names[5] = { "Aristotle", "Kant", "Spinoza", "Marx", "Russell" }; pthread_mutex_t forks[5]; const char *topic[5] = { "Spaghetti!", "Life", "Universe", "Everything", "Bathroom" }; void print(int y, int x, const char *fmt, ...) { static pthread_mutex_t scree...
1
#include <pthread.h> pthread_t *tab; int val; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void *funcThread(void *arg){ pthread_mutex_lock(&mutex); free(arg); srand((unsigned int ) pthread_self()); val += (int) (10*((double)rand())/ 32767); printf("Valeur de val : %d\\n",val); pthrea...
0
#include <pthread.h> static long sum = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void thread_clean(void* arg) { pthread_mutex_unlock(&mutex); } void* thread_func(void* arg) { for (int i = 1; i <= 1000000; ++i) { pthread_cleanup_push(thread_clean,0); pthread_mutex_lock(&mu...
1
#include <pthread.h> struct lidar_data lidar_data; pthread_mutex_t lidar_lock = PTHREAD_MUTEX_INITIALIZER; pthread_t lidarthread; const int capture_frames = 15; struct xv11lidar_data xv11_data; struct laser_frame *frames; void process_frame(struct laser_frame frame) { pthread_mutex_lock(&...
0
#include <pthread.h> static struct node * root; pthread_mutex_t listlock = PTHREAD_MUTEX_INITIALIZER; char * get_work(void){ pthread_mutex_lock(&listlock); char * dirr = 0; if(root != 0){ if(root->next != 0){ dirr = root->directory; struct n...
1
#include <pthread.h> int g = 0; pthread_mutex_t mutex; void *ThreadProc(void *arg){ int i; int l; printf("Thread %d starting to execute\\n", *((int *)arg)); for (i=0; i < 10000000; i++){ pthread_mutex_lock(&mutex); l = g; l = l + 1; g = l; pthread_mute...
0
#include <pthread.h> unsigned long Flag_Count; unsigned long Flag_Threads; unsigned long Threads_Completed; pthread_mutex_t Lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t Job_Done = PTHREAD_COND_INITIALIZER; long double *Thread_Rates; void emit_help(void); void *worker(void *ratearg);...
1
#include <pthread.h> pthread_mutex_t m; struct param{ char *frase; int numero; }; void hiloMensaje(struct param *mensa){ printf("%s %d \\n", mensa->frase, mensa->numero); } void tablas(int num){ int i=0; pthread_mutex_lock(&m); while(i<6) { printf("%d * %d = %d \\n",num,i,(i*i)); i++...
0
#include <pthread.h> int count = 0 , flag = 0 ; pthread_mutex_t mutex ; pthread_cond_t cond ; void *window1_sell(void *arg) { printf("thd1 :\\n"); while(1) { pthread_mutex_lock(&mutex); if(count > 0) { flag = 1 ; count-- ; printf("thd1 sold 1 , left :%d\\n ",count); pthr...
1
#include <pthread.h> static struct { pthread_mutex_t mutex; struct tcp_server server; } house; static void new_session(struct tcp_client *s_client, void *data) { struct command cmd; if (!tcp_client_recv(s_client, (void *)&cmd, sizeof(struct command))) { pthread_mutex_lock(&house.mutex); ...
0
#include <pthread.h> pthread_mutex_t m; int seed; int PseudoRandomUsingAtomic_nextInt(int n) { int read, nexts, nextInt_return; pthread_mutex_lock(&m); read = seed; do { nexts = __nondet_int(); } while(nexts == read || nexts == 0); assert(nexts != read); seed = nexts; pt...
1
#include <pthread.h> int g_buffer[10]; unsigned short in = 0; unsigned short out = 0; unsigned short produce_id = 0; unsigned short consume_id = 0; sem_t g_sem_full; sem_t g_sem_empty; pthread_mutex_t g_mutex; pthread_t g_thread[1 + 1]; void *consume(void *arg) { int inx = *((int *) arg);...
0
#include <pthread.h> int controladora = 0; pthread_mutex_t x_mutex; pthread_cond_t x_cond; void barreira(int nthreads) { pthread_mutex_lock(&x_mutex); controladora++; if(controladora < nthreads){ pthread_cond_wait(&x_cond, &x_mutex); } else { controladora = 0; pthread_cond_b...
1
#include <pthread.h> void *hilo1(void *p); void *hilo2(void *p); void *hilo3(void *p); void *hilo4(void *p); int flag = 0; pthread_cond_t v1; pthread_cond_t v2; pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER ; pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER ; int main(int argc, char **argv){ pth...
0
#include <pthread.h> int mdlist_pqueue_coarse_enq (struct mdlist_pqueue_head_coarse *mdlist_queue_coarse_head, struct mdlist_pqueue_node *node) { int retval; if (!mdlist_queue_coarse_head || !node) return -EINVAL; pthread_mutex_lock(&mdlist_queue_coarse_head->lock); retval = mdlist_p...
1
#include <pthread.h> static struct rsocket *sockets = 0; static int64_t num_rsockets = 0; static int64_t new_rsockets = 0; static int server_port = 0; static int hard_fail = 0; static char *hostname = 0; pthread_t server_thread; static pthread_mutex_t socket_lock = PTHREAD_MUTEX_INITIALIZER; v...
0
#include <pthread.h> int producir(); void * productor(); void * consumidor(); pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cp = PTHREAD_COND_INITIALIZER, cc = PTHREAD_COND_INITIALIZER; int in = 0, out = 0, buffer_elements = 0, buffer [10]; int main(){ pthread_t pro...
1
#include <pthread.h> void * readFunc(void * myvar); void * writeFunc(void * myvar); pthread_mutex_t lock; int a[500]; int main (int argc, char * argv[]) { pthread_t thread1, thread2; char * msg1 = "First thread"; char * msg2 = "Second thread"; int ret1, ret2; memset(a, 0, sizeof(a)); ...
0
#include <pthread.h> int klvanc_cache_alloc(struct klvanc_context_s *ctx) { ctx->cacheLines = calloc(0x10000, sizeof(struct klvanc_cache_s)); if (!ctx->cacheLines) return -1; return 0; } void klvanc_cache_free(struct klvanc_context_s *ctx) { klvanc_cache_reset(ctx); ...
1
#include <pthread.h> struct { int status; char buffer[65]; } data; pthread_t tid_1, tid_2; pthread_mutex_t mutex_x = PTHREAD_MUTEX_INITIALIZER; void *thread_1(void *arg) { char filename[20]; FILE *fp; memset(filename, '\\0', 20); strcpy(filename, arg); strcat(filename, ".1"); f...
0
#include <pthread.h> int producer(void * args); int consumer(void * args); pthread_mutex_t mutex; sem_t product; sem_t warehouse; char buffer[8][4]; int bp=0; main(int argc,char** argv) { pthread_mutex_init(&mutex,0); sem_init(&product,0,0); sem_init(&warehouse,0,8); int clone_flag,arg,retva...
1
#include <pthread.h> void test_queue_push_pop_order(void **state){ struct fsm_queue queue = create_fsm_queue(); int valueRand1 = rand(); int valueRand2 = rand(); int valueRand3 = rand(); while (valueRand1 == valueRand2){ valueRand2 = rand(); } while (valueR...
0
#include <pthread.h> static pthread_mutex_t g_glitch_log_lock = PTHREAD_MUTEX_INITIALIZER; static int g_configured = 0; static int g_use_syslog = 0; static int g_glitch_log_fd = -1; static char g_glitch_log_fname[PATH_MAX] = { 0 }; void regurgitate_fd(char *line, size_t max_line, in...
1
#include <pthread.h> pthread_mutex_t mm_mutex; void qemu_free(void *ptr) { trace_qemu_free(ptr); if ( pthread_mutex_trylock(&mm_mutex) == 0 ){ free(ptr); pthread_mutex_unlock(&mm_mutex); } else free(ptr); } static int allow_zero_malloc(void) { return 0; } void *qemu_mall...
0
#include <pthread.h> static sem_t cesta_libera_per_inserimento; static sem_t inserimento_del_produttore; pthread_mutex_t mut; pthread_cond_t avvio; int ceste_fatte=0; int prod_in_cesta=0; void* produttore(void* arg) { int id = (int)arg; while(1) { pthread_mutex_lock(&mut); pthread_cond_...
1
#include <pthread.h> void* merge(void *args); void* quicksort(void *args); int compare(const void *a, const void *b); int* listnum = 0; int segment_count; int thread_count; int remain; pthread_mutex_t m; pthread_cond_t cv; { size_t start, start2, end, num,size1,size2; } Parameter; int mai...
0
#include <pthread.h> int capacity = 0; pthread_mutex_t mylockA = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mylockB = PTHREAD_MUTEX_INITIALIZER; void *produce(void *args) { int i = 0; for (; i < 10;) { pthread_mutex_lock(&mylockA); if (capacity >= 5) { printf("缓冲区已满,无法放入产品\\n");...
1
#include <pthread.h> pthread_mutex_t passwdstruct_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t groupstruct_mutex = PTHREAD_MUTEX_INITIALIZER; char *getUsername(uid_t uid) { pthread_mutex_lock(&passwdstruct_mutex); struct passwd *userinfo = getpwuid(uid); char * ret = ...
0
#include <pthread.h> static void sensor_nano_sleep(int64_t utime) { struct timespec t; if (utime <= 0) return; t.tv_sec = (time_t)(utime / 1e9); t.tv_nsec = (long)(utime % 1000000000L); nanosleep(&t, 0); } static void *sensors_worker_internal_worker(void *arg) { struct sensors_worker_t*...
1
#include <pthread.h> void *customerMaker(); void *barberShop(); void *waitingRoom(); void checkQueue(); pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t wait_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t sleep_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t barberS...
0
#include <pthread.h> pthread_mutex_t verrou = PTHREAD_MUTEX_INITIALIZER ; pthread_cond_t condition = PTHREAD_COND_INITIALIZER ; void * monthread (void * arg){ int n = *(int *) arg ; int condition_insatisfaite = 0 ; printf("le thread (%d) attend \\n",(int)pthread_self()); pthread_mutex_lock(...
1
#include <pthread.h> int q[4]; int qsiz; pthread_mutex_t mq; void queue_init () { pthread_mutex_init (&mq, 0); qsiz = 0; } void queue_insert (int x) { int done = 0; printf ("prod: trying\\n"); while (done == 0) { pthread_mutex_lock (&mq); if (qsiz < 4) ...
0
#include <pthread.h> void* estimate_pi(void* rank); long long int num_tosses; long long int num_in_circle; int num_threads; int sums_per_thread; double pi_estimate; pthread_mutex_t lock; int main(int argc, char* argv[]) { num_tosses = strtoll(argv[1], 0, 10); num_in_circle = 0; num_threads ...
1
#include <pthread.h> int R[MAX_N+1][MAX_C+1]; int progress[MAX_N+1] = {-1}; pthread_mutex_t mut[MAX_N+1] = {PTHREAD_MUTEX_INITIALIZER}; pthread_cond_t cond[MAX_N+1] = {PTHREAD_COND_INITIALIZER}; int wait_progress(int i,int j){ int prg = -1; pthread_mutex_lock(&mut[i]); while(j > (prg=pr...
0
#include <pthread.h> int *histogramVals; float binSize; int calcHistogram (float* data, int numDataPoints, int numBins); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int main(void) { float rawData[1000000]; pthread_mutex_lock(&mutex); histogramVals = malloc(1000 * sizeof(int)); ...
1
#include <pthread.h> extern int pthread_setconcurrency(int); void *child_out(void *); pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; int service_count; int main() { service_count = 0; int sock_server; if(0 > (sock_server = socket(AF_INET, SOCK_STREAM, 0))){ fprintf(st...
0
#include <pthread.h> static int append_rdma_buffer_pool(struct rdma_buffer_pool *rbp, uint32_t size); int init_rdma_buffer_pool(struct rdma_buffer_pool *rbp, struct ibv_pd *pd) { memset(rbp, 0, sizeof(struct rdma_buffer_pool)); rbp->pd = pd; pthread_mutex_init(&rbp->lock, 0); return append_r...
1
#include <pthread.h>extern int __VERIFIER_nondet_int(void); extern void __VERIFIER_error() ; int element[(20)]; int head; int tail; int amount; } QType; pthread_mutex_t m; int __VERIFIER_nondet_int(); int stored_elements[(20)]; _Bool enqueue_flag, dequeue_flag; QType queue...
0
#include <pthread.h> struct Data *table[ 29 ]; pthread_mutex_t tablelock = PTHREAD_MUTEX_INITIALIZER; struct Data { int count; pthread_mutex_t lock; struct Data *next; int id; int number; }; struct Data *data_alloc( void ) { struct Data *data; int index; if ( (data = ma...
1
#include <pthread.h> int quit,sum; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t waitloc =PTHREAD_COND_INITIALIZER; void *thr_fn(void *arg) { int i = *(int *)arg; printf("thr_fn\\n"); if (i==0){ printf("the transfer the param success\\n"); while(i<=100){ ...
0
#include <pthread.h> static pthread_cond_t sCond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t sCondMutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t sMutexes[20]; volatile static int sTotal[20] = { 0 }; volatile static int sThreadCount = 0; volatile static int sMutexCount; volatil...
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(str...
0
#include <pthread.h> void pqsort(void*); struct TaskQueue queue; pthread_mutex_t qmutex; int *a, rec_limit; struct TaskArgs { int l, r, depth; struct ThreadPool *pool; }; void targs_set(struct TaskArgs *targs, int l, int r, int depth, struct ThreadPool *pool) { targs->l = l; ta...
1
#include <pthread.h> pthread_mutex_t lock; void *threaded(void *accountPtr) { pthread_mutex_lock(&lock); int amount = 0; printf("Please Enter an amount to be added:"); scanf("%d", &amount); if(amount > 1000000000 || amount < 0) { printf("Number entere...
0
#include <pthread.h> static uint8_t flagCollect[2]; static FILE *fp; void *RunDataService( void* ); void clearFlag( uint8_t ); void *RunDataService( void *arg ) { fp = fopen("data/test_data.csv", "w"); while (1) { for (int i=0; i< (sizeof(flagCollect)/sizeof(flagCollect[0]))...
1
#include <pthread.h> static pthread_mutex_t mlock; void th1_count( int* x ); void th2_count( int* x ); void delay( long nanosec ); int main(int argc, char** argv ) { int x = 0; pthread_mutex_init( &mlock, 0 ); pthread_t thread1, thread2; if (pthread_create(&thread1, 0, (void *)...
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, len;...
1
#include <pthread.h> int g_flag = 0; pthread_mutex_t glock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t gcond = PTHREAD_COND_INITIALIZER; void *thr_fn1(void *arg) { printf("this is thread1.\\n"); pthread_mutex_lock(&glock); if (g_flag == 2) pthread_cond_signal(&gcond); g_flag = 1; pthread...
0
#include <pthread.h> struct dpado_range_t { struct list_head entry; unsigned int conn_cnt; int pado_delay; }; static pthread_mutex_t dpado_range_lock = PTHREAD_MUTEX_INITIALIZER; static LIST_HEAD(dpado_range_list); static struct dpado_range_t *dpado_range_next; static struct dpado_range_t *d...
1
#include <pthread.h> static pthread_mutex_t mutex; char listeNomFichier[30][100]; unsigned longueur = 30; void* afficheDossier(void* nom){ char* nameC = malloc(strlen((char*)nom)*sizeof(char)); stpcpy(nameC, (char*)nom); char* nameO = malloc(strlen(nameC)*sizeof(char)); stpcpy(nameO, nameC)...
0
#include <pthread.h> int count = 0; int c = 0; pthread_mutex_t count_mutex; pthread_cond_t count_threshold_cv; void * inc_count (void* arg) { count++; pthread_mutex_lock (&count_mutex); c = 1; pthread_cond_signal (&count_threshold_cv); pthread_mutex_unlock (&count_mutex); return 0; ...
1
#include <pthread.h> int find = 0; int element; int * vector; int sizeVector,start; }infos_search; int initialise_vector(int * vector){ char buffer[50]; char * token; int sizeVector =0; if(fgets(buffer, sizeof(buffer), stdin)==0){printf("Erreur de lecture");exit(0);}; token =...
0
#include <pthread.h> int g = 0; pthread_mutex_t mutex1; pthread_mutex_t mutex2; void *myThreadFun1(void *vargp) { int i = (int)vargp; pthread_mutex_lock (&mutex1); pthread_mutex_lock (&mutex2); printf("1 Global: %d\\n", ++g); pthread_mutex_lock (&mutex2); pthread_mutex_...
1
#include <pthread.h> void *arr[32]; int rd; int wr; } queue_t; static pthread_mutex_t lock_x; static pthread_cond_t count_consumer, count_producer; static queue_t q; int enqueue(void *addr) { if (!addr) return -1; if (((q.wr + 1) % 32) == q.rd) return -1; q.arr[q.wr] = addr; q.wr ...
0
#include <pthread.h> static pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER; void *thread_a(void *arg); void *thread_b(void *arg); int main(){ int shmid = shmget(IPC_PRIVATE, sizeof(int), S_IRUSR | S_IWUSR); if (shmid==-1){ perr...
1
#include <pthread.h> pthread_mutex_t lock_x; void *connection_handler(void *socket_desc) { int sock = *(int*)socket_desc; int read_size, bytes; char *message, client_message[100], client_filename[100], client_filepath[100], server_filepath[500], file_buffer[512], username[50],...
0
#include <pthread.h> static char* resbuffer_result_string = 0; static int resbuffer_num_lines = 0; static int resbuffer_current_bufsize = 0; static int resbuffer_current_ressize = 0; static int resbuffer_async_mode = 0; static int resbuffer_async_notify = 0; static pthread_mutex_t resbuffer_l...
1
#include <pthread.h> void log_info(const char* fmt, ...) { va_list va; __builtin_va_start((va)); vprintf(fmt, va); ; } pthread_mutex_t the_mutex; pthread_cond_t condc, condp; int buffer = 0; void* producer(void* ptr) { int i; for (i=0; i<=1000; ++i) { pthread_mutex_lock(&the_mutex); ...
0
#include <pthread.h> static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; void output_init() { return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(0); now = localt...
1
#include <pthread.h> pthread_mutex_t lock; pthread_mutexattr_t lockattr; int x; void* t1(void *arg) { int err = __SMACK_nondet(); pthread_mutex_lock(&lock); err = pthread_mutex_lock(&lock); assert(35 == err); x++; pthread_mutex_unlock(&lock); err = pthread_mutex_unlock(&lock);...
0
#include <pthread.h> void scan() { if(file->nbExtension == 0 || file->premier == 0 || file->dernier == 0) return; FILE *fichier; fichier = fopen("data.dbf", "rb+"); FNode *fn; fn = malloc(sizeof(FNode)); extension *pE; pE = malloc(sizeof(extension)); fn = file->dernier; ...
1
#include <pthread.h> pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t print_request_lock = PTHREAD_MUTEX_INITIALIZER; int print_request,want_exit; void print_pthread_internal(struct pthread_internal_t * p) { pthread_mutex_lock(&print_lock); printf("\\n\\n%s called by %p\...
0
#include <pthread.h> pthread_mutex_t mutexid; pthread_mutex_t mutexres; int idcount = 0; pthread_mutex_t joinmutex[6]; int join[6]; int result[6]; int target; int sequence[(6 * 30)]; void *thread (void *arg) { int id, i, from, count, l_target; pthread_mutex_lock (&mutexid); l_t...
1
#include <pthread.h> pthread_mutex_t lock; pthread_cond_t cond_produce; pthread_cond_t cond_consume; item_t buffer[4]; volatile int counter=0; volatile int out=0; volatile int in=0; void *producerWork(void* args) { item_t item; size_t latency = (size_t)args; static int item_count = 0;...
0
#include <pthread.h> pthread_mutex_t mutex; sem_t full; sem_t empty; int pro = 0; int pro_id = 0; int con = 0; int con_id = 0; void *producer(); void *consumer(); void print_buff(); int main(){ return 0; } void *producer(){ int id = ++ pro_id; while(1){ sleep(1); se...
1
#include <pthread.h> struct{ int file_descript; char* url[15]; char buffer[10]; int bytes_read_form_file; int bytes_write_in_file; }file_structure; int bytes_write = 0; int bytes_read = 0; int fd[2]; int eof = -1; pthread_mutex_t mutex; sem_t empty, full; pthread_t t_A,t_B;...
0
#include <pthread.h> struct msg { struct msg *m_next; }; struct msg *workq; pthread_cond_t qready = PTHREAD_COND_INITIALIZER; pthread_mutex_t qlock = PTHREAD_MUTEX_INITIALIZER; void process_msg(void) { struct msg *mp; for (;;) { pthread_mutex_lock(&qlock); while (workq == 0) p...
1
#include <pthread.h> extern unsigned volatile int *lock; FILE *fileout_basicmath; FILE *fileout_qsort; FILE *fileout_susancorners; FILE *fileout_dijkstra; FILE *filein_qsort; FILE *filein_susancorners; FILE *filein_dijkstra; volatile int procCounter = 0; volatile int barrier_in = 0; v...
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(void) { struct foo *fp; int idx; if((fp = malloc(sizeof(struct foo))) != 0) { fp->f...
1
#include <pthread.h> int fnLoadWeights( void ) { return TRUE; } int fnStockCompare( const void* p1, const void* p2 ) { return strcmp( (char *)p1, (char *)p2 ); } int fnLoadStocks( void ) { char szBuffer[LINE_BUFFER_SIZE]; char szListFile[BUFFER_SIZE]; char szStock[BUFFER_S...
0
#include <pthread.h> int cuenta = 0; pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cuenta_ok = PTHREAD_COND_INITIALIZER; int thread_ids[4] = {0,1,2,3}; int usa_timed; int usa_broad; void *inc_cuenta(void *idp) { int i=0; int *my_id = idp; ...
1
#include <pthread.h> pthread_mutex_t *lvls; pthread_cond_t *cond_lvls; int dronWeight[5]; int floorWeight[5]; int totalWeight[5]; void *dron(void *arg) { int cont = 0; while(cont < 5) { pthread_mutex_lock(lvls+cont); if(dronWeight[(int)arg]+totalWeight[cont] > floorWeight[cont]...
0
#include <pthread.h> int buf[5], f, index1 = 0; pthread_mutex_t mutex; pthread_cond_t full, empty; int cntr = 0, i = 0, cntr1 = 0; void *producer (void *arg) { for (cntr = 0; cntr < 10; cntr++) { printf ("\\n\\tProducer: Checking if buffer has some space"); pthread_mutex_lock (&...
1
#include <pthread.h> static void eatIfOk(int i); static int leftNghbr(int i); static int rightNghbr(int i); static pthread_mutex_t dpMutex; static pthread_cond_t okToEat[N_PHIL]; static state_t state[N_PHIL]; void dpPickup(int i) { pthread_mutex_lock(&dpMutex); state[i] = ...
0
#include <pthread.h> char **buffer1; char **buffer2; pthread_mutex_t mutex, mutex2; pthread_cond_t spaceAvailable, itemAvailable; int count1, count2; int in1, in2, out1, out2; int fp_green, fp_black, fp_output; void produce( void *ptr ); void consume( void *ptr ); void main() { buffer1 ...
1
#include <pthread.h> int q[2]; int qsiz; pthread_mutex_t mq; void queue_init () { pthread_mutex_init (&mq, 0); qsiz = 0; } void queue_insert (int x) { int done = 0; printf ("prod: trying\\n"); while (done == 0) { pthread_mutex_lock (&mq); if (qsiz < 2) ...
0
#include <pthread.h> pthread_mutex_t locks[1]; int x = 0; void *thread0(void *arg) { pthread_mutex_lock(locks + 0); pthread_mutex_unlock(locks + 0); x = 1; pthread_exit(0); } void *thread1(void *arg) { x = 0; pthread_mutex_lock(locks + 0); x = 2; pthread_mutex_u...
1
#include <pthread.h> void *(*process) (void *arg); void *arg; struct worker *next; } CThread_workder; pthread_mutex_t queue_lock; pthread_cond_t queue_ready; CThread_workder *queue_head; int shutdown; pthread_t *thread_id; int max_thread_num; int cur_queue_size; } CThread_pool; CThread...
0
#include <pthread.h> struct thread_args { int tid; int inc; int loop; }; int count = 0; pthread_mutex_t count_mutex; void *inc_count(void *arg) { int i,loc; struct thread_args *my_args = (struct thread_args*) arg; loc = 0; for (i = 0; i < my_args->loop; i++) { pth...
1
#include <pthread.h> int buffer=0; pthread_mutex_t mutex; void delay(int secs) { time_t beg = time(0), end = beg + secs; do { } while (time(0) < end); } void *read(void *i){ long identify=(long)i; int flag; for(flag=0;flag<4;flag++){ pthread_mutex_loc...
0
#include <pthread.h> static int gDone = 0; static int kMaxIterations = 10; struct thread_closure { int tid; int nice; int iters; }; static pthread_mutex_t gTheBigLock; static pthread_cond_t gDoneCond; static void Report(struct thread_closure *tc) { pthread_mutex_lock(&gTheBigLock); prin...
1
#include <pthread.h> static pthread_mutex_t *mptr; int g_LockFileFd = -1; int ProcessMutex_file_init(char * pathname) { int fd = -1; fd = open(pathname, O_RDWR | O_CREAT, 0666); if(fd < 0) { perror("open error"); exit(-1); } return fd; } int ProcessMutex_wr_lock(int fd) { if(fd < ...
0
#include <pthread.h> pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condition_mutex = PTHREAD_COND_INITIALIZER; void add_money (int *account) { int i = 0; for (i = 0; i < 5; i++) { pthread_mutex_lock(&(account_mutex)); (*account) += 10; printf("[Add %d] W...
1
#include <pthread.h> pthread_mutex_t mutex; int max_clients = 100; pthread_t thread[5]; pthread_mutex_t mut; const int LISTEN_BACKLOG = 50; char msg[100]; int clients[100]; int setnonblocking(int sock) { int opts; opts = fcntl(sock, F_GETFL); if (opts < 0) { return 0;...
0
#include <pthread.h> pthread_t threads[2]; pthread_mutex_t mutexsum; int thread_data_count; { int send_ready; char *mystring; }thread_data; thread_data thread_data_array[128]; int call_socket(char *hostname, char *portnum) { struct addrinfo hints, *res; int sockfd; memset(&hints, 0, s...
1
#include <pthread.h> char Buffer1[4][20]; char Buffer2[4][20]; int in1 = 0; int in2 = 0; int count1 = 0; int count2 = 0; int end = 2; pthread_mutex_t lock, lock2; pthread_cond_t SpaceAvailable, ItemAvailable; void copytoBuffers(char writing[]){ if (count1 == 4) { strcpy (Buffer2[in...
0
#include <pthread.h> struct node { int datum; struct node *next; }; struct head { pthread_mutex_t lock; struct node *first; struct head *next; } *list; pthread_mutex_t list_lock = PTHREAD_MUTEX_INITIALIZER; void init_node (struct node *p, int x) { p->datum = x; p->next = 0; } vo...
1
#include <pthread.h> static int reset_timer (struct thread_data *, const int, const int); void on_motion_detect (void *arg) { int b; ssize_t s; uint64_t u; struct thread_data *tdata = arg; pthread_mutex_lock (&tdata->wiring_mutex); b = digitalRead (tdata->pir_pin) == ...
0
#include <pthread.h> int depth = 1; pthread_mutex_t depthlock; void *md(void *thid) { int cur_dir = 0; int me = *(int *) thid; int ret = 0; char dname[10]; char dirpath[16000]; while (depth <= 1000) { pthread_mutex_lock (&depthlock); cur_dir = dept...
1
#include <pthread.h>extern void __VERIFIER_error() ; int element[(20)]; int head; int tail; int amount; } QType; pthread_mutex_t m; int __VERIFIER_nondet_int(); int stored_elements[(20)]; _Bool enqueue_flag, dequeue_flag; QType queue; int init(QType *q) { q->head=0; ...
0
#include <pthread.h> struct shm { pthread_mutex_t gprs_mutex_start; pthread_cond_t gprs_cond_start; pthread_mutex_t gprs_mutex_end; pthread_cond_t gprs_cond_end; pthread_mutex_t beep_mutex_start; pthread_cond_t beep_cond_start; pthread_mutex_t beep_mutex_end; pthread_cond_t beep_cond...
1
#include <pthread.h> int contador; pthread_mutex_t mutex; sem_t semaforo_productor; void agregar(char c); void quitar(); void * productor() { while(1) { char c = 'a' + rand()%24; agregar(c); usleep(1000); } } void * consumidor() { while(1) { quitar(); usleep(1000);...
0
#include <pthread.h> int nitems; struct { pthread_mutex_t mutex; int buff[MAXNITEMS]; int nput; int nval; } shared = {PTHREAD_MUTEX_INITIALIZER}; void *produce(void *); void *consume(void *); int main(int argc, char **argv) { int i, nthreads, count[MAXNTHREADS]; pthread...
1
#include <pthread.h> static dev_t __ashmem_rdev; static pthread_mutex_t __ashmem_lock = PTHREAD_MUTEX_INITIALIZER; static int __ashmem_open_locked() { int ret; struct stat st; int fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR)); if (fd < 0) { return fd; ...
0
#include <pthread.h> pthread_mutex_t seconds_mutex = PTHREAD_MUTEX_INITIALIZER; unsigned int seconds_remaining = 0; unsigned int clock_active = 0; void *clock_thread_start(void *arg); int main (int argc, char **argv, char **envp) { pthread_t server, acceptor, clock; int s,...
1
#include <pthread.h> int i = 0; pthread_mutex_t lock; void *thread_1(){ pthread_mutex_lock(&lock); for (int count = 0; count < 1000001; count++) { i++; } printf("%s\\n", "Done incrementing"); pthread_mutex_unlock(&lock); pthread_exit(0); } void *thread_2(){ pthread_mutex_lock(&loc...
0