Skip to content
Snippets Groups Projects
Commit f6046419 authored by Dana-Maria CĂRUNTU's avatar Dana-Maria CĂRUNTU
Browse files

add logic for sort True for 2 threads (40p)

parent bdb1ec6b
No related branches found
No related tags found
No related merge requests found
Pipeline #92385 passed
......@@ -13,9 +13,8 @@ pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
void consumer_thread(so_consumer_ctx_t *ctx)
{
/* TODO: implement consumer thread */
// (void) ctx;
so_packet_t packet;
/* TODO: implement consumer thread */
so_packet_t packet;
while (1) {
......@@ -26,7 +25,7 @@ void consumer_thread(so_consumer_ctx_t *ctx)
pthread_mutex_unlock(&log_mutex);
break;
}
pthread_mutex_unlock(&log_mutex);
char log[PKT_SZ];
so_action_t decision = process_packet(&packet);
unsigned long pkt_hash = packet_hash(&packet);
......@@ -39,36 +38,37 @@ char log[PKT_SZ];
pthread_mutex_unlock(&log_mutex);
//pthread_mutex_unlock(&ctx->log_mutex);
}
return NULL;
// (void) ctx;
return NULL;
}
int create_consumers(pthread_t *tids,
int num_consumers,
struct so_ring_buffer_t *rb,
const char *out_filename)
int num_consumers,
struct so_ring_buffer_t *rb,
const char *out_filename)
{
// (void) tids;
// (void) num_consumers;
// (void) rb;
// (void) out_filename;
FILE *log_file = fopen(out_filename, "w");
// (void) tids;
// (void) num_consumers;
// (void) rb;
// (void) out_filename;
FILE *log_file = fopen(out_filename, "w");
if (!log_file) {
perror("Error opening file");
return -1;
}
pthread_mutex_t log_mutex;
pthread_mutex_init(&log_mutex, NULL);
for (int i = 0; i < num_consumers; i++) {
/*
* TODO: Launch consumer threads
**/
for (int i = 0; i < num_consumers; i++) {
so_consumer_ctx_t *ctx = malloc(sizeof(so_consumer_ctx_t));
ctx->producer_rb = rb;
ctx->log_file = log_file;
ctx->log_mutex = log_mutex;
pthread_create(&tids[i], NULL, consumer_thread, ctx);
}
pthread_create(&tids[i], NULL, consumer_thread, ctx);
}
return num_consumers;
}
return num_consumers;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment