[問題] pthread 的 mutex 在什麼情況下會deadlock ?
(mandelbrot set)
在pthread+xlib programing下,由於xlib 不是thread safe,所以要用 mutex_lock包起來。
但是 mutex_lock 後來也好像卡住了? http://tinyurl.com/yhmxxos
沒卡住的時候就會有error message:
X Error of failed request: BadRequest (invalid request code or no such operation)
Major opcode of failed request: 0 ()
Serial number of failed request: 277465
Current serial number in output stream: 285661
把 xlib 相關的那兩行 mark掉就沒事了,所以問題應該是 mutex ?
我想問的是,mutex 不是那樣用嗎? 還是mutex要另外注意什麼?
還是 xlib+pthread 有其它的做法?
還是要用 conditional variable ?
我一直搞不懂 conditional variable 與 mutex 是差在哪裡
thanks
platform: solaris + sun studio c 5.9 compiler
(per thread code)
for(int i = tid; i < X_RESN; i += num_threads)
for(int j = 0; j < Y_RESN; j++) {
c.real = ((float) j - MIN)/WIDTH;
c.imag = ((float) i - MIN)/WIDTH;
color = cal_pixel(c);
color = color | color << 4 | color << 8;
pthread_mutex_lock(&mutex);
/* here */
XSetForeground(data->display, data->gc, color);
XDrawPoint(data->display, data->win, data->gc, j, i);
/*******/
pthread_mutex_unlock(&mutex);
}
XFlush(data->display);
pthread_exit(NULL);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.114.203.27
→
12/01 06:30, , 1F
12/01 06:30, 1F
→
12/01 06:30, , 2F
12/01 06:30, 2F
→
12/01 08:04, , 3F
12/01 08:04, 3F
→
12/01 08:04, , 4F
12/01 08:04, 4F
→
12/01 08:12, , 5F
12/01 08:12, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章