[OSy] thread_join na neplatnou adresu vs. testy

loki loki at matfyz.cz
Wed Nov 9 18:01:04 CET 2005


Dobry den,

zajimalo by me, jak se ma chovat thread_join, jemuz je predana neplatna 
adresa (neukazuje na existujici vlakno)
v podstate me napadli 2 moznosti:
1) ohlasi EINVAL (neni vlakno),
2) ohlasi EOK (vlakno uz neni)

prijde mi logictejsi varianta (1), protoze jinac se da uspesne volat 
join na libovolnou adresu v pameti.

Ale vsimnul jsem si jedne zajimave veci v testu thread1 je tam

*while* (thread_a_active || thread_b_active) {
		int result;

		*if* (thread_a_active) {
			result = thread_join_timeout (thread_a,
				JOIN_TIMEOUT_MS * 1000);
			*if* (result == EOK) {
				/// we joined the thread/
				thread_a_active = 0;
			}
		}

		*if* (thread_b_active) {
			result = thread_join_timeout (thread_b, 0);
			*if* (result == EOK) {
				/// we joined the thread/
				thread_b_active = 0;
			}
		}

		printk ("*");
	}

tedy pokud bude vlakno a nebo b zruseno mezi dvemi kontrolnimi cykly (nic tomu nebrani, nikdo na nej neceka, neni detached),
zasekne se test v nekonecne smycce, protoze bude furt dostavat EINVAL. Nemel by spis thread_x_active nastavovat sam thread_x?
pak by proslo i u EINVAL.

S pozdravem

Jiri Zouhar




More information about the NSWI004 mailing list