View difference between Paste ID: VqRrhXPD and Kmp5dUPL
SHOW: | | - or go back to the newest paste.
1-
#include <stdlib.h>
1+
2-
#include <stdio.h>
2+
3-
#include <pthread.h>
3+
int main() {
4-
#include <errno.h>
4+
alive_threads = number_of_threads;
5-
#include <string.h>
5+
6-
#include <sys/types.h>
6+
		pthread_create(&thread_id[i], NULL, thread_function, NULL)
7-
#include <sys/stat.h>
7+
8-
#include <fcntl.h>
8+
9-
#include <unistd.h>
9+
10-
#include <time.h>
10+
11
	}
12-
int thread_quantity;
12+
13-
int buffer_size;
13+
void clean(void *) {
14-
char *requested_file_name;
14+
  alive_threads--;
15-
char *requested_word;
15+
16
void *thread_function(void *data) {
17-
int file_des = 0;
17+
while (1) {
18-
int created_threads = 0;
18+
  pthread_cleanup_push(clean, NULL);
19-
int alive_threads;
19+
	pthread_mutex_lock(&reading_mutex)
20
	//some code...
21
	pthread_mutex_unlock(&reading_mutex);
22-
pthread_t *thread_id = NULL;
22+
	if (bytes_readed > 0) {
23-
off_t file_size;
23+
           //no, don't need that code
24-
pthread_key_t buffer;
24+
				
25
	pthread_cleanup_pop(1);
26-
void usage() {
26+
	pthread_cancel(pthread_self())
27-
exit(1);
27+
28
}
29-
void err_exit(char *);
29+
30-
void* thread_function(void *);
30+
31-
void clean_thread(void *);
31+
32-
void clean_tsd_buffer(void *); //thread specific data
32+
33
       The pthread_cleanup_pop() function removes the routine at  the  top  of
34-
int main(int argc, char *argv[]) {
34+
35-
	int i;
35+
36-
	if (argc != 5) {
36+
37-
		usage();
37+
38-
	} else {
38+
39-
		thread_quantity = (int) strtol(argv[1], NULL, 10);
39+
40-
		alive_threads = thread_quantity;
40+
41-
		thread_id = malloc(sizeof(pthread_t) * thread_quantity);
41+
42-
		requested_file_name = argv[2];
42+
43-
		buffer_size = (int) strtol(argv[3], NULL, 10);
43+
44-
		if (errno) {
44+
45-
			usage();
45+
46-
		}
46+
47-
		requested_word = argv[4];
47+
48
49-
	if ((file_des = open(requested_file_name, O_RDONLY)) == -1) {
49+
50-
		err_exit("Error: open(requested_file_name)");
50+
51
52-
	if ((file_size = lseek(file_des, 0, SEEK_END)) == (off_t) -1) {
52+
53-
		err_exit("Error: lseek(file_des, 0, SEEK_END)");
53+
54
       respectively.   For  this  reason, the caller must ensure that call