Войти в систему

Home
    - Создать дневник
    - Написать в дневник
       - Подробный режим

LJ.Rossia.org
    - Новости сайта
    - Общие настройки
    - Sitemap
    - Оплата
    - ljr-fif

Редактировать...
    - Настройки
    - Список друзей
    - Дневник
    - Картинки
    - Пароль
    - Вид дневника

Сообщества

Настроить S2

Помощь
    - Забыли пароль?
    - FAQ
    - Тех. поддержка



Пишет yigal_s ([info]yigal_s)
@ 2006-12-22 21:11:00


Previous Entry  Add to memories!  Tell a Friend!  Next Entry
забавная мелочевка (переключение тредов)
Написал функциональность, позволяющую переходить с одного windows thread на другой в пределах одной функции.


int main() // ms windows only
{
printf("%d\n", GetCurrentThreadId());
LeapThread();
printf("%d\n", GetCurrentThreadId());
return 0;

}

void LeapThread()
{
... // some code
}

Output:

272
1832


(Добавить комментарий)


[info]skiasonar@lj
2006-12-22 19:58 (ссылка)
Kewl stuff! :)

(Ответить)


[info]moshe_kravchik@lj
2006-12-24 09:07 (ссылка)
I 'm not sure that you meant this, but the following code will produce the result that you show:

void LeapThread()
{
_asm
{
mov eax,fs:[0x18] //TIB
mov ecx,dword ptr [eax+24h]
add ecx,1
mov dword ptr [eax+24h],ecx
}

}

I'm not aware of any way to actually case the CPU to change the thread...

(Ответить) (Ветвь дискуссии)


(Анонимно)
2006-12-24 09:31 (ссылка)
One could also reimplement GetCurrentThreadId() to get the result I've shown.

But my result is merely changing a thread, not two integers printed.

(Ответить) (Уровень выше)